
(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 9 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 (- (tanh (/ t y)) (tanh (/ x y)))))
(if (<= (+ (* t_1 (* z y)) x) 1e+308)
(fma (* t_1 y) z x)
(* (* (- (/ t x) 1.0) x) z))))
double code(double x, double y, double z, double t) {
double t_1 = tanh((t / y)) - tanh((x / y));
double tmp;
if (((t_1 * (z * y)) + x) <= 1e+308) {
tmp = fma((t_1 * y), z, x);
} else {
tmp = (((t / x) - 1.0) * x) * z;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(tanh(Float64(t / y)) - tanh(Float64(x / y))) tmp = 0.0 if (Float64(Float64(t_1 * Float64(z * y)) + x) <= 1e+308) tmp = fma(Float64(t_1 * y), z, x); else tmp = Float64(Float64(Float64(Float64(t / x) - 1.0) * x) * z); end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[Tanh[N[(t / y), $MachinePrecision]], $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(t$95$1 * N[(z * y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], 1e+308], N[(N[(t$95$1 * y), $MachinePrecision] * z + x), $MachinePrecision], N[(N[(N[(N[(t / x), $MachinePrecision] - 1.0), $MachinePrecision] * x), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \tanh \left(\frac{t}{y}\right) - \tanh \left(\frac{x}{y}\right)\\
\mathbf{if}\;t\_1 \cdot \left(z \cdot y\right) + x \leq 10^{+308}:\\
\;\;\;\;\mathsf{fma}\left(t\_1 \cdot y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\frac{t}{x} - 1\right) \cdot x\right) \cdot z\\
\end{array}
\end{array}
if (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) < 1e308Initial program 97.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6499.0
Applied rewrites99.0%
if 1e308 < (+.f64 x (*.f64 (*.f64 y z) (-.f64 (tanh.f64 (/.f64 t y)) (tanh.f64 (/.f64 x y))))) Initial program 32.5%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites100.0%
Final simplification99.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (* (- (/ t y) (tanh (/ x y))) y) z x))) (if (<= z -7e-35) t_1 (if (<= z 2.4e-18) (fma (- x) z x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((((t / y) - tanh((x / y))) * y), z, x);
double tmp;
if (z <= -7e-35) {
tmp = t_1;
} else if (z <= 2.4e-18) {
tmp = fma(-x, z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(Float64(Float64(t / y) - tanh(Float64(x / y))) * y), z, x) tmp = 0.0 if (z <= -7e-35) tmp = t_1; elseif (z <= 2.4e-18) tmp = fma(Float64(-x), z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -7e-35], t$95$1, If[LessEqual[z, 2.4e-18], N[((-x) * z + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right) \cdot y, z, x\right)\\
\mathbf{if}\;z \leq -7 \cdot 10^{-35}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.4 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -6.99999999999999992e-35 or 2.39999999999999994e-18 < z Initial program 89.5%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f6495.4
Applied rewrites95.4%
Taylor expanded in t around 0
lower-/.f6455.0
Applied rewrites55.0%
if -6.99999999999999992e-35 < z < 2.39999999999999994e-18Initial program 99.6%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6474.1
Applied rewrites74.1%
Taylor expanded in t around 0
Applied rewrites79.9%
(FPCore (x y z t) :precision binary64 (if (<= y 2.45e+160) (+ (* (- (/ t y) (tanh (/ x y))) (* z y)) x) (fma (- t x) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 2.45e+160) {
tmp = (((t / y) - tanh((x / y))) * (z * y)) + x;
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 2.45e+160) tmp = Float64(Float64(Float64(Float64(t / y) - tanh(Float64(x / y))) * Float64(z * y)) + x); else tmp = fma(Float64(t - x), z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 2.45e+160], N[(N[(N[(N[(t / y), $MachinePrecision] - N[Tanh[N[(x / y), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(z * y), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.45 \cdot 10^{+160}:\\
\;\;\;\;\left(\frac{t}{y} - \tanh \left(\frac{x}{y}\right)\right) \cdot \left(z \cdot y\right) + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if y < 2.4500000000000001e160Initial program 95.2%
Taylor expanded in t around 0
lower-/.f6456.9
Applied rewrites56.9%
if 2.4500000000000001e160 < y Initial program 83.8%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6486.0
Applied rewrites86.0%
Final simplification60.6%
(FPCore (x y z t) :precision binary64 (if (<= y 8e-86) (fma (* z y) (/ t y) x) (fma (- t x) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 8e-86) {
tmp = fma((z * y), (t / y), x);
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 8e-86) tmp = fma(Float64(z * y), Float64(t / y), x); else tmp = fma(Float64(t - x), z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 8e-86], N[(N[(z * y), $MachinePrecision] * N[(t / y), $MachinePrecision] + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 8 \cdot 10^{-86}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot y, \frac{t}{y}, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if y < 8.00000000000000068e-86Initial program 94.0%
Taylor expanded in y around inf
lower-/.f64N/A
lower--.f6438.0
Applied rewrites38.0%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6438.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6438.0
Applied rewrites38.0%
Taylor expanded in t around inf
Applied rewrites48.9%
if 8.00000000000000068e-86 < y Initial program 93.3%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6469.1
Applied rewrites69.1%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- t x) z))) (if (<= z -4.8e+72) t_1 (if (<= z 4.3e-7) (fma (- x) z x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (t - x) * z;
double tmp;
if (z <= -4.8e+72) {
tmp = t_1;
} else if (z <= 4.3e-7) {
tmp = fma(-x, z, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(t - x) * z) tmp = 0.0 if (z <= -4.8e+72) tmp = t_1; elseif (z <= 4.3e-7) tmp = fma(Float64(-x), z, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[z, -4.8e+72], t$95$1, If[LessEqual[z, 4.3e-7], N[((-x) * z + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(t - x\right) \cdot z\\
\mathbf{if}\;z \leq -4.8 \cdot 10^{+72}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{-7}:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -4.8000000000000002e72 or 4.3000000000000001e-7 < z Initial program 87.8%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6442.5
Applied rewrites42.5%
Taylor expanded in z around inf
Applied rewrites42.3%
if -4.8000000000000002e72 < z < 4.3000000000000001e-7Initial program 99.6%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6469.5
Applied rewrites69.5%
Taylor expanded in t around 0
Applied rewrites74.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- x) z))) (if (<= x -6.7e-136) t_1 (if (<= x 1.9e-14) (* t z) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = -x * z;
double tmp;
if (x <= -6.7e-136) {
tmp = t_1;
} else if (x <= 1.9e-14) {
tmp = t * z;
} else {
tmp = t_1;
}
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) :: t_1
real(8) :: tmp
t_1 = -x * z
if (x <= (-6.7d-136)) then
tmp = t_1
else if (x <= 1.9d-14) then
tmp = t * z
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = -x * z;
double tmp;
if (x <= -6.7e-136) {
tmp = t_1;
} else if (x <= 1.9e-14) {
tmp = t * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = -x * z tmp = 0 if x <= -6.7e-136: tmp = t_1 elif x <= 1.9e-14: tmp = t * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(-x) * z) tmp = 0.0 if (x <= -6.7e-136) tmp = t_1; elseif (x <= 1.9e-14) tmp = Float64(t * z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = -x * z; tmp = 0.0; if (x <= -6.7e-136) tmp = t_1; elseif (x <= 1.9e-14) tmp = t * z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[((-x) * z), $MachinePrecision]}, If[LessEqual[x, -6.7e-136], t$95$1, If[LessEqual[x, 1.9e-14], N[(t * z), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(-x\right) \cdot z\\
\mathbf{if}\;x \leq -6.7 \cdot 10^{-136}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-14}:\\
\;\;\;\;t \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -6.6999999999999998e-136 or 1.9000000000000001e-14 < x Initial program 95.5%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6462.0
Applied rewrites62.0%
Taylor expanded in z around inf
Applied rewrites23.2%
Taylor expanded in t around 0
Applied rewrites19.7%
if -6.6999999999999998e-136 < x < 1.9000000000000001e-14Initial program 91.4%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6448.2
Applied rewrites48.2%
Taylor expanded in t around inf
Applied rewrites27.4%
(FPCore (x y z t) :precision binary64 (if (<= y 1660000000.0) (fma (- x) z x) (fma (- t x) z x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= 1660000000.0) {
tmp = fma(-x, z, x);
} else {
tmp = fma((t - x), z, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= 1660000000.0) tmp = fma(Float64(-x), z, x); else tmp = fma(Float64(t - x), z, x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, 1660000000.0], N[((-x) * z + x), $MachinePrecision], N[(N[(t - x), $MachinePrecision] * z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1660000000:\\
\;\;\;\;\mathsf{fma}\left(-x, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(t - x, z, x\right)\\
\end{array}
\end{array}
if y < 1.66e9Initial program 94.5%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6450.1
Applied rewrites50.1%
Taylor expanded in t around 0
Applied rewrites48.0%
if 1.66e9 < y Initial program 91.2%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6475.7
Applied rewrites75.7%
(FPCore (x y z t) :precision binary64 (* (- t x) z))
double code(double x, double y, double z, double t) {
return (t - x) * z;
}
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 = (t - x) * z
end function
public static double code(double x, double y, double z, double t) {
return (t - x) * z;
}
def code(x, y, z, t): return (t - x) * z
function code(x, y, z, t) return Float64(Float64(t - x) * z) end
function tmp = code(x, y, z, t) tmp = (t - x) * z; end
code[x_, y_, z_, t_] := N[(N[(t - x), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\left(t - x\right) \cdot z
\end{array}
Initial program 93.8%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6456.1
Applied rewrites56.1%
Taylor expanded in z around inf
Applied rewrites27.1%
(FPCore (x y z t) :precision binary64 (* t z))
double code(double x, double y, double z, double t) {
return t * z;
}
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 = t * z
end function
public static double code(double x, double y, double z, double t) {
return t * z;
}
def code(x, y, z, t): return t * z
function code(x, y, z, t) return Float64(t * z) end
function tmp = code(x, y, z, t) tmp = t * z; end
code[x_, y_, z_, t_] := N[(t * z), $MachinePrecision]
\begin{array}{l}
\\
t \cdot z
\end{array}
Initial program 93.8%
Taylor expanded in y around inf
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f6456.1
Applied rewrites56.1%
Taylor expanded in t around inf
Applied rewrites15.9%
(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 2024248
(FPCore (x y z t)
:name "SynthBasics:moogVCF from YampaSynth-0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (* y (* z (- (tanh (/ t y)) (tanh (/ x y)))))))
(+ x (* (* y z) (- (tanh (/ t y)) (tanh (/ x y))))))