
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
(FPCore (x y z) :precision binary64 (+ x (* y (- z x))))
double code(double x, double y, double z) {
return x + (y * (z - x));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y * (z - x))
end function
public static double code(double x, double y, double z) {
return x + (y * (z - x));
}
def code(x, y, z): return x + (y * (z - x))
function code(x, y, z) return Float64(x + Float64(y * Float64(z - x))) end
function tmp = code(x, y, z) tmp = x + (y * (z - x)); end
code[x_, y_, z_] := N[(x + N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \left(z - x\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -3.6e+124)
(* y z)
(if (<= y -6.3e+29)
t_0
(if (<= y -1e-9)
(* y z)
(if (<= y 1.7e-10)
x
(if (or (<= y 270000000000.0)
(and (not (<= y 2.6e+242)) (<= y 1.15e+303)))
(* y z)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.6e+124) {
tmp = y * z;
} else if (y <= -6.3e+29) {
tmp = t_0;
} else if (y <= -1e-9) {
tmp = y * z;
} else if (y <= 1.7e-10) {
tmp = x;
} else if ((y <= 270000000000.0) || (!(y <= 2.6e+242) && (y <= 1.15e+303))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-3.6d+124)) then
tmp = y * z
else if (y <= (-6.3d+29)) then
tmp = t_0
else if (y <= (-1d-9)) then
tmp = y * z
else if (y <= 1.7d-10) then
tmp = x
else if ((y <= 270000000000.0d0) .or. (.not. (y <= 2.6d+242)) .and. (y <= 1.15d+303)) then
tmp = y * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.6e+124) {
tmp = y * z;
} else if (y <= -6.3e+29) {
tmp = t_0;
} else if (y <= -1e-9) {
tmp = y * z;
} else if (y <= 1.7e-10) {
tmp = x;
} else if ((y <= 270000000000.0) || (!(y <= 2.6e+242) && (y <= 1.15e+303))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -3.6e+124: tmp = y * z elif y <= -6.3e+29: tmp = t_0 elif y <= -1e-9: tmp = y * z elif y <= 1.7e-10: tmp = x elif (y <= 270000000000.0) or (not (y <= 2.6e+242) and (y <= 1.15e+303)): tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -3.6e+124) tmp = Float64(y * z); elseif (y <= -6.3e+29) tmp = t_0; elseif (y <= -1e-9) tmp = Float64(y * z); elseif (y <= 1.7e-10) tmp = x; elseif ((y <= 270000000000.0) || (!(y <= 2.6e+242) && (y <= 1.15e+303))) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -3.6e+124) tmp = y * z; elseif (y <= -6.3e+29) tmp = t_0; elseif (y <= -1e-9) tmp = y * z; elseif (y <= 1.7e-10) tmp = x; elseif ((y <= 270000000000.0) || (~((y <= 2.6e+242)) && (y <= 1.15e+303))) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -3.6e+124], N[(y * z), $MachinePrecision], If[LessEqual[y, -6.3e+29], t$95$0, If[LessEqual[y, -1e-9], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.7e-10], x, If[Or[LessEqual[y, 270000000000.0], And[N[Not[LessEqual[y, 2.6e+242]], $MachinePrecision], LessEqual[y, 1.15e+303]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{+124}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -6.3 \cdot 10^{+29}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1 \cdot 10^{-9}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 270000000000 \lor \neg \left(y \leq 2.6 \cdot 10^{+242}\right) \land y \leq 1.15 \cdot 10^{+303}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.59999999999999986e124 or -6.2999999999999998e29 < y < -1.00000000000000006e-9 or 1.70000000000000007e-10 < y < 2.7e11 or 2.5999999999999998e242 < y < 1.15e303Initial program 100.0%
Taylor expanded in z around inf 76.1%
Taylor expanded in x around 0 74.0%
if -3.59999999999999986e124 < y < -6.2999999999999998e29 or 2.7e11 < y < 2.5999999999999998e242 or 1.15e303 < y Initial program 100.0%
Taylor expanded in z around 0 69.9%
mul-1-neg69.9%
distribute-lft-neg-out69.9%
*-commutative69.9%
Simplified69.9%
Taylor expanded in y around inf 69.5%
associate-*r*69.5%
mul-1-neg69.5%
Simplified69.5%
if -1.00000000000000006e-9 < y < 1.70000000000000007e-10Initial program 100.0%
Taylor expanded in z around inf 99.5%
Taylor expanded in x around inf 75.2%
Final simplification73.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (* y z))) (t_1 (* y (- x))))
(if (<= y -1.15e+125)
t_0
(if (<= y -2.7e+30)
t_1
(if (<= y 950000000000.0)
t_0
(if (or (<= y 2.75e+242) (not (<= y 4.2e+301))) t_1 (* y z)))))))
double code(double x, double y, double z) {
double t_0 = x + (y * z);
double t_1 = y * -x;
double tmp;
if (y <= -1.15e+125) {
tmp = t_0;
} else if (y <= -2.7e+30) {
tmp = t_1;
} else if (y <= 950000000000.0) {
tmp = t_0;
} else if ((y <= 2.75e+242) || !(y <= 4.2e+301)) {
tmp = t_1;
} else {
tmp = y * z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = x + (y * z)
t_1 = y * -x
if (y <= (-1.15d+125)) then
tmp = t_0
else if (y <= (-2.7d+30)) then
tmp = t_1
else if (y <= 950000000000.0d0) then
tmp = t_0
else if ((y <= 2.75d+242) .or. (.not. (y <= 4.2d+301))) then
tmp = t_1
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x + (y * z);
double t_1 = y * -x;
double tmp;
if (y <= -1.15e+125) {
tmp = t_0;
} else if (y <= -2.7e+30) {
tmp = t_1;
} else if (y <= 950000000000.0) {
tmp = t_0;
} else if ((y <= 2.75e+242) || !(y <= 4.2e+301)) {
tmp = t_1;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): t_0 = x + (y * z) t_1 = y * -x tmp = 0 if y <= -1.15e+125: tmp = t_0 elif y <= -2.7e+30: tmp = t_1 elif y <= 950000000000.0: tmp = t_0 elif (y <= 2.75e+242) or not (y <= 4.2e+301): tmp = t_1 else: tmp = y * z return tmp
function code(x, y, z) t_0 = Float64(x + Float64(y * z)) t_1 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -1.15e+125) tmp = t_0; elseif (y <= -2.7e+30) tmp = t_1; elseif (y <= 950000000000.0) tmp = t_0; elseif ((y <= 2.75e+242) || !(y <= 4.2e+301)) tmp = t_1; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x + (y * z); t_1 = y * -x; tmp = 0.0; if (y <= -1.15e+125) tmp = t_0; elseif (y <= -2.7e+30) tmp = t_1; elseif (y <= 950000000000.0) tmp = t_0; elseif ((y <= 2.75e+242) || ~((y <= 4.2e+301))) tmp = t_1; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.15e+125], t$95$0, If[LessEqual[y, -2.7e+30], t$95$1, If[LessEqual[y, 950000000000.0], t$95$0, If[Or[LessEqual[y, 2.75e+242], N[Not[LessEqual[y, 4.2e+301]], $MachinePrecision]], t$95$1, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x + y \cdot z\\
t_1 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1.15 \cdot 10^{+125}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -2.7 \cdot 10^{+30}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 950000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 2.75 \cdot 10^{+242} \lor \neg \left(y \leq 4.2 \cdot 10^{+301}\right):\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -1.15000000000000006e125 or -2.6999999999999999e30 < y < 9.5e11Initial program 100.0%
Taylor expanded in z around inf 93.5%
if -1.15000000000000006e125 < y < -2.6999999999999999e30 or 9.5e11 < y < 2.75000000000000011e242 or 4.1999999999999999e301 < y Initial program 100.0%
Taylor expanded in z around 0 69.9%
mul-1-neg69.9%
distribute-lft-neg-out69.9%
*-commutative69.9%
Simplified69.9%
Taylor expanded in y around inf 69.5%
associate-*r*69.5%
mul-1-neg69.5%
Simplified69.5%
if 2.75000000000000011e242 < y < 4.1999999999999999e301Initial program 100.0%
Taylor expanded in z around inf 75.3%
Taylor expanded in x around 0 75.7%
Final simplification85.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -7.5e+78) (not (<= x 1.4e-70))) (- x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e+78) || !(x <= 1.4e-70)) {
tmp = x - (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((x <= (-7.5d+78)) .or. (.not. (x <= 1.4d-70))) then
tmp = x - (x * y)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -7.5e+78) || !(x <= 1.4e-70)) {
tmp = x - (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -7.5e+78) or not (x <= 1.4e-70): tmp = x - (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -7.5e+78) || !(x <= 1.4e-70)) tmp = Float64(x - Float64(x * y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -7.5e+78) || ~((x <= 1.4e-70))) tmp = x - (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -7.5e+78], N[Not[LessEqual[x, 1.4e-70]], $MachinePrecision]], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{+78} \lor \neg \left(x \leq 1.4 \cdot 10^{-70}\right):\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -7.49999999999999934e78 or 1.4e-70 < x Initial program 100.0%
Taylor expanded in z around 0 89.3%
mul-1-neg89.3%
distribute-lft-neg-out89.3%
*-commutative89.3%
Simplified89.3%
*-commutative89.3%
distribute-lft-neg-out89.3%
unsub-neg89.3%
Applied egg-rr89.3%
if -7.49999999999999934e78 < x < 1.4e-70Initial program 100.0%
Taylor expanded in z around inf 90.9%
Final simplification90.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -7.5e-10) (not (<= y 2.45e-17))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e-10) || !(y <= 2.45e-17)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((y <= (-7.5d-10)) .or. (.not. (y <= 2.45d-17))) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -7.5e-10) || !(y <= 2.45e-17)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -7.5e-10) or not (y <= 2.45e-17): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -7.5e-10) || !(y <= 2.45e-17)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -7.5e-10) || ~((y <= 2.45e-17))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -7.5e-10], N[Not[LessEqual[y, 2.45e-17]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-10} \lor \neg \left(y \leq 2.45 \cdot 10^{-17}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -7.49999999999999995e-10 or 2.45000000000000006e-17 < y Initial program 100.0%
Taylor expanded in z around inf 50.6%
Taylor expanded in x around 0 49.9%
if -7.49999999999999995e-10 < y < 2.45000000000000006e-17Initial program 100.0%
Taylor expanded in z around inf 99.5%
Taylor expanded in x around inf 75.2%
Final simplification62.3%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 74.7%
Taylor expanded in x around inf 38.6%
Final simplification38.6%
herbie shell --seed 2024115
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))