
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); 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]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))
double code(double x, double y, double z, double t) {
return x + ((y * z) * (tanh((t / y)) - tanh((x / y))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y * z) * (tanh((t / y)) - tanh((x / y))))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * z) * (Math.tanh((t / y)) - Math.tanh((x / y))));
}
def code(x, y, z, t): return x + ((y * z) * (math.tanh((t / y)) - math.tanh((x / y))))
function code(x, y, z, t) return Float64(x + Float64(Float64(y * z) * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))))) end
function tmp = code(x, y, z, t) tmp = x + ((y * z) * (tanh((t / y)) - tanh((x / y)))); 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]
\begin{array}{l}
\\
x + \left(y \cdot z\right) \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)
\end{array}
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (+ x (* (- (tanh (/ t y)) (tanh (/ x y))) (* y z)))))
(if (<= t_1 (- INFINITY))
(+ x (* z (- t x)))
(if (<= t_1 4e+306) t_1 (+ x (- (* z t) (* z x)))))))
double code(double x, double y, double z, double t) {
double t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (y * z));
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = x + (z * (t - x));
} else if (t_1 <= 4e+306) {
tmp = t_1;
} else {
tmp = x + ((z * t) - (z * x));
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = x + ((Math.tanh((t / y)) - Math.tanh((x / y))) * (y * z));
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = x + (z * (t - x));
} else if (t_1 <= 4e+306) {
tmp = t_1;
} else {
tmp = x + ((z * t) - (z * x));
}
return tmp;
}
def code(x, y, z, t): t_1 = x + ((math.tanh((t / y)) - math.tanh((x / y))) * (y * z)) tmp = 0 if t_1 <= -math.inf: tmp = x + (z * (t - x)) elif t_1 <= 4e+306: tmp = t_1 else: tmp = x + ((z * t) - (z * x)) return tmp
function code(x, y, z, t) t_1 = Float64(x + Float64(Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) * Float64(y * z))) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(x + Float64(z * Float64(t - x))); elseif (t_1 <= 4e+306) tmp = t_1; else tmp = Float64(x + Float64(Float64(z * t) - Float64(z * x))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x + ((tanh((t / y)) - tanh((x / y))) * (y * z)); tmp = 0.0; if (t_1 <= -Inf) tmp = x + (z * (t - x)); elseif (t_1 <= 4e+306) tmp = t_1; else tmp = x + ((z * t) - (z * x)); end tmp_2 = tmp; end
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[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e+306], t$95$1, N[(x + N[(N[(z * t), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x + \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(y \cdot z\right)\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\mathbf{elif}\;t_1 \leq 4 \cdot 10^{+306}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;x + \left(z \cdot t - z \cdot x\right)\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < -inf.0Initial program 55.3%
Taylor expanded in y around inf 100.0%
if -inf.0 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 4.00000000000000007e306Initial program 99.5%
if 4.00000000000000007e306 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 37.6%
Taylor expanded in y around inf 99.8%
sub-neg99.8%
distribute-rgt-in99.9%
+-commutative99.9%
Applied egg-rr99.9%
+-commutative99.9%
*-commutative99.9%
distribute-lft-neg-out99.9%
unsub-neg99.9%
Applied egg-rr99.9%
Final simplification99.6%
(FPCore (x y z t) :precision binary64 (if (<= y 9.5e+232) (fma y (* z (- (tanh (/ t y)) (tanh (/ x y)))) x) (+ x (* z (- t x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 9.5e+232) {
tmp = fma(y, (z * (tanh((t / y)) - tanh((x / y)))), x);
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 9.5e+232) tmp = fma(y, Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))), x); else tmp = Float64(x + Float64(z * Float64(t - x))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 9.5e+232], N[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.5 \cdot 10^{+232}:\\
\;\;\;\;\mathsf{fma}\left(y, z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if y < 9.4999999999999996e232Initial program 94.7%
+-commutative94.7%
associate-*l*97.8%
fma-def97.8%
Simplified97.8%
if 9.4999999999999996e232 < y Initial program 66.1%
Taylor expanded in y around inf 96.8%
Final simplification97.7%
(FPCore (x y z t) :precision binary64 (if (<= y 1.4e+182) (+ x (* y (* z (tanh (/ t y))))) (+ x (* z (- t x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.4e+182) {
tmp = x + (y * (z * tanh((t / y))));
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 1.4d+182) then
tmp = x + (y * (z * tanh((t / y))))
else
tmp = x + (z * (t - x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1.4e+182) {
tmp = x + (y * (z * Math.tanh((t / y))));
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 1.4e+182: tmp = x + (y * (z * math.tanh((t / y)))) else: tmp = x + (z * (t - x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 1.4e+182) tmp = Float64(x + Float64(y * Float64(z * tanh(Float64(t / y))))); else tmp = Float64(x + Float64(z * Float64(t - x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 1.4e+182) tmp = x + (y * (z * tanh((t / y)))); else tmp = x + (z * (t - x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 1.4e+182], N[(x + N[(y * N[(z * N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.4 \cdot 10^{+182}:\\
\;\;\;\;x + y \cdot \left(z \cdot \tanh \left(\frac{t}{y}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if y < 1.40000000000000003e182Initial program 94.9%
Taylor expanded in x around 0 24.0%
associate-*r*23.8%
associate-/r*23.8%
div-sub23.8%
rec-exp23.8%
rec-exp23.8%
tanh-def-a79.4%
associate-*r*81.0%
Simplified81.0%
if 1.40000000000000003e182 < y Initial program 74.3%
Taylor expanded in y around inf 97.8%
Final simplification83.0%
(FPCore (x y z t) :precision binary64 (if (<= y 6.4e-16) x (+ x (- (* z t) (* z x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6.4e-16) {
tmp = x;
} else {
tmp = x + ((z * t) - (z * x));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 6.4d-16) then
tmp = x
else
tmp = x + ((z * t) - (z * x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 6.4e-16) {
tmp = x;
} else {
tmp = x + ((z * t) - (z * x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 6.4e-16: tmp = x else: tmp = x + ((z * t) - (z * x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 6.4e-16) tmp = x; else tmp = Float64(x + Float64(Float64(z * t) - Float64(z * x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 6.4e-16) tmp = x; else tmp = x + ((z * t) - (z * x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 6.4e-16], x, N[(x + N[(N[(z * t), $MachinePrecision] - N[(z * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.4 \cdot 10^{-16}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + \left(z \cdot t - z \cdot x\right)\\
\end{array}
\end{array}
if y < 6.40000000000000046e-16Initial program 95.1%
+-commutative95.1%
associate-*l*97.4%
fma-def97.4%
Simplified97.4%
Taylor expanded in y around 0 66.6%
if 6.40000000000000046e-16 < y Initial program 83.6%
Taylor expanded in y around inf 86.4%
sub-neg86.4%
distribute-rgt-in86.4%
+-commutative86.4%
Applied egg-rr86.4%
+-commutative86.4%
*-commutative86.4%
distribute-lft-neg-out86.4%
unsub-neg86.4%
Applied egg-rr86.4%
Final simplification71.2%
(FPCore (x y z t) :precision binary64 (if (<= y 8.4e-16) x (+ x (* z (- t x)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 8.4e-16) {
tmp = x;
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 8.4d-16) then
tmp = x
else
tmp = x + (z * (t - x))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 8.4e-16) {
tmp = x;
} else {
tmp = x + (z * (t - x));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 8.4e-16: tmp = x else: tmp = x + (z * (t - x)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 8.4e-16) tmp = x; else tmp = Float64(x + Float64(z * Float64(t - x))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 8.4e-16) tmp = x; else tmp = x + (z * (t - x)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 8.4e-16], x, N[(x + N[(z * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8.4 \cdot 10^{-16}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \left(t - x\right)\\
\end{array}
\end{array}
if y < 8.4000000000000004e-16Initial program 95.1%
+-commutative95.1%
associate-*l*97.4%
fma-def97.4%
Simplified97.4%
Taylor expanded in y around 0 66.6%
if 8.4000000000000004e-16 < y Initial program 83.6%
Taylor expanded in y around inf 86.4%
Final simplification71.2%
(FPCore (x y z t) :precision binary64 (if (<= y 2.15e-10) x (+ x (* z t))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.15e-10) {
tmp = x;
} else {
tmp = x + (z * t);
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (y <= 2.15d-10) then
tmp = x
else
tmp = x + (z * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.15e-10) {
tmp = x;
} else {
tmp = x + (z * t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= 2.15e-10: tmp = x else: tmp = x + (z * t) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= 2.15e-10) tmp = x; else tmp = Float64(x + Float64(z * t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= 2.15e-10) tmp = x; else tmp = x + (z * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.15e-10], x, N[(x + N[(z * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.15 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot t\\
\end{array}
\end{array}
if y < 2.15000000000000007e-10Initial program 95.1%
+-commutative95.1%
associate-*l*97.4%
fma-def97.4%
Simplified97.4%
Taylor expanded in y around 0 66.6%
if 2.15000000000000007e-10 < y Initial program 83.6%
Taylor expanded in x around 0 30.3%
associate-*r*29.5%
associate-/r*29.5%
div-sub29.5%
rec-exp29.5%
rec-exp29.5%
tanh-def-a63.6%
associate-*r*69.7%
Simplified69.7%
Taylor expanded in y around inf 62.4%
+-commutative62.4%
*-commutative62.4%
Simplified62.4%
Final simplification65.7%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 92.5%
+-commutative92.5%
associate-*l*96.3%
fma-def96.3%
Simplified96.3%
Taylor expanded in y around 0 58.8%
Final simplification58.8%
(FPCore (x y z t) :precision binary64 (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
double code(double x, double y, double z, double t) {
return x + (y * (z * (tanh((t / y)) - tanh((x / y)))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + (y * (z * (tanh((t / y)) - tanh((x / y)))))
end function
public static double code(double x, double y, double z, double t) {
return x + (y * (z * (Math.tanh((t / y)) - Math.tanh((x / y)))));
}
def code(x, y, z, t): return x + (y * (z * (math.tanh((t / y)) - math.tanh((x / y)))))
function code(x, y, z, t) return Float64(x + Float64(y * Float64(z * Float64(tanh(Float64(t / y)) - tanh(Float64(x / y)))))) end
function tmp = code(x, y, z, t) tmp = x + (y * (z * (tanh((t / y)) - tanh((x / y))))); end
code[x_, y_, z_, t_] := N[(x + N[(y * N[(z * N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z \cdot \left(\tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\right)\right)
\end{array}
herbie shell --seed 2023301
(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))))))