diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1ff0c42 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b06e864 --- /dev/null +++ b/.gitignore @@ -0,0 +1,212 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studio 2015 cache/options directory +.vs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml diff --git a/IMPressive/IMPressive.sln b/IMPressive/IMPressive.sln new file mode 100644 index 0000000..fe9d80f --- /dev/null +++ b/IMPressive/IMPressive.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IMPressive", "IMPressive\IMPressive.csproj", "{5CC42C69-40E1-401E-AFD5-6EE51F6E4056}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5CC42C69-40E1-401E-AFD5-6EE51F6E4056}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CC42C69-40E1-401E-AFD5-6EE51F6E4056}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CC42C69-40E1-401E-AFD5-6EE51F6E4056}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CC42C69-40E1-401E-AFD5-6EE51F6E4056}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/IMPressive/IMPressive/Constructors.cs b/IMPressive/IMPressive/Constructors.cs new file mode 100644 index 0000000..8dc9793 --- /dev/null +++ b/IMPressive/IMPressive/Constructors.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Hassium.Functions; +using Hassium.HassiumObjects; +using Hassium.Interpreter; +using IMPression; + +namespace IMPressive +{ + public class Constructors : ILibrary + { + public static Dictionary GetConstants() + { + var res = new Dictionary(); + + res.Add("I", new HComplex(0, 1)); + + #region Constants + var cts = new HassiumObject(); + cts.Attributes.Add("Pi", new InternalFunction(x => (HComplex)Constants.Pi, 0, true)); + cts.Attributes.Add("E", new InternalFunction(x => (HComplex)Constants.E, 0, true)); + cts.Attributes.Add("Catalan", new InternalFunction(x => (HComplex)Constants.Catalan, 0, true)); + cts.Attributes.Add("Degree", new InternalFunction(x => (HComplex)Constants.Degree, 0, true)); + cts.Attributes.Add("Epsilon", new InternalFunction(x => (HComplex)Constants.Epsilon, 0, true)); + cts.Attributes.Add("EulerGamma", new InternalFunction(x => (HComplex)Constants.EulerGamma, 0, true)); + cts.Attributes.Add("Glaisher", new InternalFunction(x => (HComplex)Constants.Glaisher, 0, true)); + cts.Attributes.Add("Khinchin", new InternalFunction(x => (HComplex)Constants.Khinchin, 0, true)); + cts.Attributes.Add("Phi", new InternalFunction(x => (HComplex)Constants.Phi, 0, true)); + cts.Attributes.Add("SpeedOfLight", new InternalFunction(x => (HComplex)Constants.SpeedOfLight, 0, true)); + cts.Attributes.Add("Tau", new InternalFunction(x => (HComplex)Constants.Tau, 0, true)); + + res.Add("Constants", cts); + #endregion + + #region Functions + var imp = new HassiumObject(); + + var funcs = + typeof(Functions).GetMethods(BindingFlags.Public | + BindingFlags.Static); + var ln = ""; + try + { + foreach (var x in funcs) + { + if (Attribute.IsDefined(x, typeof(MathFunc))) + if ((Attribute.GetCustomAttribute(x, typeof(MathFunc)) as MathFunc).Hide) continue; + var n = x.Name; + ln = n; + if (Attribute.IsDefined(x, typeof(MathFunc))) + if ((Attribute.GetCustomAttribute(x, typeof(MathFunc)) as MathFunc).Name != "") + n = (Attribute.GetCustomAttribute(x, typeof(MathFunc)) as MathFunc).Name; + + if (imp.Attributes.Any(f => f.Key == n)) continue; + + if(funcs.Any(f => f.Name == n && f.GetParameters().Length != x.GetParameters().Length)) + { + var overloads = + funcs.Where(f => f.Name == n && f.GetParameters().Length != x.GetParameters().Length); + var parameters = overloads.Select(f => f.GetParameters().Length).ToList(); + parameters.Insert(0, x.GetParameters().Length); + + + imp.Attributes.Add(n, new InternalFunction(a => + { + return new HComplex((Complex)overloads.First(f => f.GetParameters().Length == a.Length) + .Invoke(null, a.Select(y => (object) y.HComplex().Value).ToArray())); + }, parameters.ToArray())); + } + else imp.Attributes.Add(n, new InternalFunction(a => new HComplex((Complex)x.Invoke(null, a.Select(y => (object)y.HComplex().Value).ToArray())), x.GetParameters().Length)); + } + } + catch + { + throw new ParseException("Error while loading function: " + ln, -1); + } + + + imp.Attributes.Add("integrate", + new InternalFunction( + x => + new HComplex(Functions.Integrate( + y => HassiumMethod.GetFunc1(x[0])(new HComplex(y)).HComplex().Value, x[1].HComplex().Value, + x[2].HComplex().Value)), 3)); + + + res.Add("IMP", imp); + #endregion + + return res; + } + + [IntFunc("Complex", true, new []{0, 1, 2})] + public static HassiumObject Complex(HassiumObject[] args) + { + if(args.Length == 0) return new HComplex(0, 0); + if(args.Length == 1) return new HComplex(args[0].HDouble().Value, 0); + else return new HComplex(args[0].HDouble().Value, args[1].HDouble().Value); + } + } +} diff --git a/IMPressive/IMPressive/HComplex.cs b/IMPressive/IMPressive/HComplex.cs new file mode 100644 index 0000000..84066f4 --- /dev/null +++ b/IMPressive/IMPressive/HComplex.cs @@ -0,0 +1,128 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Hassium.Functions; +using Hassium.HassiumObjects; +using Hassium.HassiumObjects.Types; +using Hassium.Interpreter; +using IMPression; + +namespace IMPressive +{ + public class HComplex : HassiumObject + { + public double Real + { + get { return Value.Real; } + set { Value = new Complex(value, Imaginary); } + } + + public double Imaginary + { + get { return Value.Imaginary; } + set { Value = new Complex(Real, value); } + } + + public HComplex(Complex c) : this(c.Real, c.Imaginary) + { + + } + + public HComplex(double r, double i) : this() + { + Value = new Complex(r, i); + } + + public HComplex() + { + Value = new Complex(0, 0); + + Attributes.Add("real", new HassiumProperty("real", x => Real, (self, x) => Real = x[0].HDouble().Value)); + Attributes.Add("imaginary", new HassiumProperty("imaginary", x => Imaginary, (self, x) => Imaginary = x[0].HDouble().Value)); + Attributes.Add("imag", new HassiumProperty("imag", x => Imaginary, (self, x) => Imaginary = x[0].HDouble().Value)); + + Attributes.Add("module", new HassiumProperty("module", x => (double)Value.Module, null, true)); + Attributes.Add("argument", new HassiumProperty("argument", x => (double)Value.Argument, null, true)); + Attributes.Add("conjugate", new HassiumProperty("conjugate", x => (double)Value.Conjugate, null, true)); + + Attributes.Add("__add", new InternalFunction(Add, -1)); + Attributes.Add("__substract", new InternalFunction(Substract, -1)); + Attributes.Add("__multiply", new InternalFunction(Multiply, -1)); + Attributes.Add("__divide", new InternalFunction(Divide, -1)); + + Attributes.Add("__compare", new InternalFunction(x => + { + var v = x[0].HComplex().Value; + if (v > Value) return 1; + if (v < Value) return -1; + return 0; + }, 1)); + + Attributes.Add("__pow", new InternalFunction(x => new HComplex(Functions.Pow(Value, x[0].HComplex().Value)), 1)); + Attributes.Add("__root", new InternalFunction(x => new HComplex(Functions.NthRoot(Value, x[0].HComplex().Value)), 1)); + + Attributes.Add("negate", new InternalFunction(Negate, 0)); + + Attributes.Add("square", new InternalFunction(x => new HComplex(Value.Square()), 0)); + } + + public HassiumObject Negate(HassiumObject[] args) + { + return new HComplex(-Value); + } + + public HassiumObject Add(HassiumObject[] args) + { + return new HComplex(args.Select(x => x.HComplex().Value).Sum() + Value); + } + + public HassiumObject Substract(HassiumObject[] args) + { + return new HComplex(Value - args.Select(x => x.HComplex().Value).Sum()); + } + + public HassiumObject Multiply(HassiumObject[] args) + { + return new HComplex(Value * args.Select(x => x.HComplex().Value).Aggregate(Complex.One, (x, y) => x * y)); + } + + public HassiumObject Divide(HassiumObject[] args) + { + return new HComplex(Value * args.Select(x => 1 / x.HComplex().Value).Aggregate(Complex.One, (x, y) => x * y)); + } + + public Complex Value { get; private set; } + + public static implicit operator HComplex(HassiumDouble d) + { + return new HComplex(d.Value, 0); + } + + public static implicit operator HComplex(Complex c) + { + return new HComplex(c.Real, c.Imaginary); + } + + public static explicit operator Complex(HComplex c) + { + return new Complex(c.Real, c.Imaginary); + } + + public override string ToString() + { + return Value.ToString(); + } + } + + public static class Extensions + { + public static HComplex HComplex(this HassiumObject obj) + { + if (obj is HassiumDouble || obj is HassiumInt) return obj.HDouble(); + if (obj is HComplex) return (HComplex) obj; + throw new ParseException("Only double and int can be cast to Complex", -1); + } + } +} diff --git a/IMPressive/IMPressive/IMPressive.csproj b/IMPressive/IMPressive/IMPressive.csproj new file mode 100644 index 0000000..6f84378 --- /dev/null +++ b/IMPressive/IMPressive/IMPressive.csproj @@ -0,0 +1,62 @@ + + + + + Debug + AnyCPU + {5CC42C69-40E1-401E-AFD5-6EE51F6E4056} + Library + Properties + IMPressive + IMPressive + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\Hassium\src\Hassium\bin\Debug\Hassium.exe + + + ..\..\..\IMPression\IMPression\bin\Debug\IMPression.dll + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/IMPressive/IMPressive/Properties/AssemblyInfo.cs b/IMPressive/IMPressive/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..afbc902 --- /dev/null +++ b/IMPressive/IMPressive/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Les informations générales relatives à un assembly dépendent de +// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations +// associées à un assembly. +[assembly: AssemblyTitle("IMPressive")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("IMPressive")] +[assembly: AssemblyCopyright("Copyright © zdimension 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly +// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de +// COM, affectez la valeur true à l'attribut ComVisible sur ce type. +[assembly: ComVisible(false)] + +// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM +[assembly: Guid("5cc42c69-40e1-401e-afd5-6ee51f6e4056")] + +// Les informations de version pour un assembly se composent des quatre valeurs suivantes : +// +// Version principale +// Version secondaire +// Numéro de build +// Révision +// +// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut +// en utilisant '*', comme indiqué ci-dessous : +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/IMPressive/IMPressive/bin/Debug/IMPression.dll b/IMPressive/IMPressive/bin/Debug/IMPression.dll new file mode 100644 index 0000000..8a9ed94 Binary files /dev/null and b/IMPressive/IMPressive/bin/Debug/IMPression.dll differ