| Alternative 1 | |
|---|---|
| Error | 2.28% |
| Cost | 19904 |
\[\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)
\]
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* z y)))))
(if (<= t_1 (- INFINITY))
(* z (- t x))
(if (<= t_1 5e+304) t_1 (- (* z t) (* z x))))))double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
double code(double x, double y, double z, double t) {
double t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = z * (t - x);
} else if (t_1 <= 5e+304) {
tmp = t_1;
} else {
tmp = (z * t) - (z * x);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
public static double code(double x, double y, double z, double t) {
double t_1 = x + ((Math.tanh((t / y)) - Math.tanh((x / y))) * (z * y));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = z * (t - x);
} else if (t_1 <= 5e+304) {
tmp = t_1;
} else {
tmp = (z * t) - (z * x);
}
return tmp;
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
def code(x, y, z, t): t_1 = x + ((math.tanh((t / y)) - math.tanh((x / y))) * (z * y)) tmp = 0 if t_1 <= -math.inf: tmp = z * (t - x) elif t_1 <= 5e+304: tmp = t_1 else: tmp = (z * t) - (z * x) return tmp
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function code(x, y, z, t) t_1 = Float64(x + Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * Float64(z * y))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(z * Float64(t - x)); elseif (t_1 <= 5e+304) tmp = t_1; else tmp = Float64(Float64(z * t) - Float64(z * x)); end return tmp end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); end
function tmp_2 = code(x, y, z, t) t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (z * y)); tmp = 0.0; if (t_1 <= -Inf) tmp = z * (t - x); elseif (t_1 <= 5e+304) tmp = t_1; else tmp = (z * t) - (z * x); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * z), $MachinePrecision] * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x + N[(N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e+304], t$95$1, N[(N[(z * t), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision]]]]
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\begin{array}{l}
t_1 := x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right)\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;z \cdot \left(t - x\right)\\
\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+304}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;z \cdot t - z \cdot x\\
\end{array}
Results
| Original | 7.11% |
|---|---|
| Target | 3.05% |
| Herbie | 1.59% |
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -inf.0Initial program 100
Simplified1.74
[Start]100 | \[ x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\] |
|---|---|
+-commutative [=>]100 | \[ \color{blue}{\left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x}
\] |
*-commutative [=>]100 | \[ \color{blue}{\left(z \cdot y\right)} \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x
\] |
associate-*l* [=>]1.74 | \[ \color{blue}{z \cdot \left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)} + x
\] |
fma-def [=>]1.74 | \[ \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)}
\] |
Taylor expanded in z around inf 97.13
Simplified100
[Start]97.13 | \[ y \cdot \left(\left(\left(\frac{1}{e^{\frac{x}{y}} \cdot \left(e^{\frac{x}{y}} + \frac{1}{e^{\frac{x}{y}}}\right)} + \frac{e^{\frac{t}{y}}}{e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}}\right) - \left(\frac{e^{\frac{x}{y}}}{e^{\frac{x}{y}} + \frac{1}{e^{\frac{x}{y}}}} + \frac{1}{e^{\frac{t}{y}} \cdot \left(e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}\right)}\right)\right) \cdot z\right)
\] |
|---|---|
*-commutative [=>]97.13 | \[ y \cdot \color{blue}{\left(z \cdot \left(\left(\frac{1}{e^{\frac{x}{y}} \cdot \left(e^{\frac{x}{y}} + \frac{1}{e^{\frac{x}{y}}}\right)} + \frac{e^{\frac{t}{y}}}{e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}}\right) - \left(\frac{e^{\frac{x}{y}}}{e^{\frac{x}{y}} + \frac{1}{e^{\frac{x}{y}}}} + \frac{1}{e^{\frac{t}{y}} \cdot \left(e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}\right)}\right)\right)\right)}
\] |
Taylor expanded in y around inf 0.04
if -inf.0 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 4.9999999999999997e304Initial program 1.1
if 4.9999999999999997e304 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 92.72
Simplified31.56
[Start]92.72 | \[ x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\] |
|---|---|
+-commutative [=>]92.72 | \[ \color{blue}{\left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x}
\] |
*-commutative [=>]92.72 | \[ \color{blue}{\left(z \cdot y\right)} \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) + x
\] |
associate-*l* [=>]31.56 | \[ \color{blue}{z \cdot \left(y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)} + x
\] |
fma-def [=>]31.56 | \[ \color{blue}{\mathsf{fma}\left(z, y \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)}
\] |
Taylor expanded in z around inf 97.96
Simplified97.98
[Start]97.96 | \[ y \cdot \left(\left(\left(\frac{1}{e^{\frac{x}{y}} \cdot \left(e^{\frac{x}{y}} + \frac{1}{e^{\frac{x}{y}}}\right)} + \frac{e^{\frac{t}{y}}}{e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}}\right) - \left(\frac{e^{\frac{x}{y}}}{e^{\frac{x}{y}} + \frac{1}{e^{\frac{x}{y}}}} + \frac{1}{e^{\frac{t}{y}} \cdot \left(e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}\right)}\right)\right) \cdot z\right)
\] |
|---|---|
*-commutative [=>]97.96 | \[ y \cdot \color{blue}{\left(z \cdot \left(\left(\frac{1}{e^{\frac{x}{y}} \cdot \left(e^{\frac{x}{y}} + \frac{1}{e^{\frac{x}{y}}}\right)} + \frac{e^{\frac{t}{y}}}{e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}}\right) - \left(\frac{e^{\frac{x}{y}}}{e^{\frac{x}{y}} + \frac{1}{e^{\frac{x}{y}}}} + \frac{1}{e^{\frac{t}{y}} \cdot \left(e^{\frac{t}{y}} + \frac{1}{e^{\frac{t}{y}}}\right)}\right)\right)\right)}
\] |
Taylor expanded in y around inf 99.91
Taylor expanded in t around 0 14.16
Applied egg-rr14.16
Final simplification1.59
| Alternative 1 | |
|---|---|
| Error | 2.28% |
| Cost | 19904 |
| Alternative 2 | |
|---|---|
| Error | 16.41% |
| Cost | 13645 |
| Alternative 3 | |
|---|---|
| Error | 30.98% |
| Cost | 7508 |
| Alternative 4 | |
|---|---|
| Error | 15.87% |
| Cost | 7504 |
| Alternative 5 | |
|---|---|
| Error | 14.55% |
| Cost | 7240 |
| Alternative 6 | |
|---|---|
| Error | 29.34% |
| Cost | 849 |
| Alternative 7 | |
|---|---|
| Error | 24.14% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Error | 24.15% |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Error | 36.41% |
| Cost | 585 |
| Alternative 10 | |
|---|---|
| Error | 28.32% |
| Cost | 585 |
| Alternative 11 | |
|---|---|
| Error | 35.05% |
| Cost | 456 |
| Alternative 12 | |
|---|---|
| Error | 35.99% |
| Cost | 64 |
herbie shell --seed 2023102
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:herbie-target
(+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))