
(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 8 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 (fma y (- z x) x))
double code(double x, double y, double z) {
return fma(y, (z - x), x);
}
function code(x, y, z) return fma(y, Float64(z - x), x) end
code[x_, y_, z_] := N[(y * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, z - x, x\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -1.7e+259)
(* y z)
(if (<= y -1.58e+38)
t_0
(if (<= y -1e-118) (* y z) (if (<= y 0.00112) x t_0))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -1.7e+259) {
tmp = y * z;
} else if (y <= -1.58e+38) {
tmp = t_0;
} else if (y <= -1e-118) {
tmp = y * z;
} else if (y <= 0.00112) {
tmp = x;
} 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 <= (-1.7d+259)) then
tmp = y * z
else if (y <= (-1.58d+38)) then
tmp = t_0
else if (y <= (-1d-118)) then
tmp = y * z
else if (y <= 0.00112d0) then
tmp = x
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 <= -1.7e+259) {
tmp = y * z;
} else if (y <= -1.58e+38) {
tmp = t_0;
} else if (y <= -1e-118) {
tmp = y * z;
} else if (y <= 0.00112) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -1.7e+259: tmp = y * z elif y <= -1.58e+38: tmp = t_0 elif y <= -1e-118: tmp = y * z elif y <= 0.00112: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -1.7e+259) tmp = Float64(y * z); elseif (y <= -1.58e+38) tmp = t_0; elseif (y <= -1e-118) tmp = Float64(y * z); elseif (y <= 0.00112) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -1.7e+259) tmp = y * z; elseif (y <= -1.58e+38) tmp = t_0; elseif (y <= -1e-118) tmp = y * z; elseif (y <= 0.00112) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -1.7e+259], N[(y * z), $MachinePrecision], If[LessEqual[y, -1.58e+38], t$95$0, If[LessEqual[y, -1e-118], N[(y * z), $MachinePrecision], If[LessEqual[y, 0.00112], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1.7 \cdot 10^{+259}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -1.58 \cdot 10^{+38}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1 \cdot 10^{-118}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 0.00112:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.69999999999999995e259 or -1.58e38 < y < -9.99999999999999985e-119Initial program 100.0%
sub-neg100.0%
distribute-rgt-in91.4%
Applied egg-rr91.4%
associate-+r+91.4%
distribute-lft-neg-out91.4%
unsub-neg91.4%
+-commutative91.4%
*-commutative91.4%
Applied egg-rr91.4%
Taylor expanded in z around inf 61.2%
if -1.69999999999999995e259 < y < -1.58e38 or 0.0011199999999999999 < y Initial program 100.0%
Taylor expanded in x around inf 60.8%
mul-1-neg60.8%
unsub-neg60.8%
Simplified60.8%
sub-neg60.8%
distribute-rgt-in60.7%
*-un-lft-identity60.7%
distribute-lft-neg-in60.7%
unsub-neg60.7%
Applied egg-rr60.7%
Taylor expanded in y around inf 60.7%
mul-1-neg60.7%
distribute-rgt-neg-out60.7%
Simplified60.7%
if -9.99999999999999985e-119 < y < 0.0011199999999999999Initial program 100.0%
Taylor expanded in y around 0 72.5%
Final simplification65.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.65e-71) (not (<= z 3.6e+107))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.65e-71) || !(z <= 3.6e+107)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
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 ((z <= (-2.65d-71)) .or. (.not. (z <= 3.6d+107))) then
tmp = y * z
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.65e-71) || !(z <= 3.6e+107)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.65e-71) or not (z <= 3.6e+107): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.65e-71) || !(z <= 3.6e+107)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.65e-71) || ~((z <= 3.6e+107))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.65e-71], N[Not[LessEqual[z, 3.6e+107]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.65 \cdot 10^{-71} \lor \neg \left(z \leq 3.6 \cdot 10^{+107}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -2.65e-71 or 3.5999999999999998e107 < z Initial program 100.0%
sub-neg100.0%
distribute-rgt-in88.8%
Applied egg-rr88.8%
associate-+r+88.8%
distribute-lft-neg-out88.8%
unsub-neg88.8%
+-commutative88.8%
*-commutative88.8%
Applied egg-rr88.8%
Taylor expanded in z around inf 75.9%
if -2.65e-71 < z < 3.5999999999999998e107Initial program 100.0%
Taylor expanded in x around inf 88.3%
mul-1-neg88.3%
unsub-neg88.3%
Simplified88.3%
Final simplification83.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.8e-72) (not (<= z 8.8e+97))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.8e-72) || !(z <= 8.8e+97)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
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 ((z <= (-5.8d-72)) .or. (.not. (z <= 8.8d+97))) then
tmp = y * (z - x)
else
tmp = x * (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.8e-72) || !(z <= 8.8e+97)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.8e-72) or not (z <= 8.8e+97): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.8e-72) || !(z <= 8.8e+97)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x * Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.8e-72) || ~((z <= 8.8e+97))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.8e-72], N[Not[LessEqual[z, 8.8e+97]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.8 \cdot 10^{-72} \lor \neg \left(z \leq 8.8 \cdot 10^{+97}\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -5.79999999999999995e-72 or 8.8000000000000003e97 < z Initial program 100.0%
sub-neg100.0%
distribute-rgt-in88.1%
Applied egg-rr88.1%
associate-+r+88.1%
distribute-lft-neg-out88.1%
unsub-neg88.1%
+-commutative88.1%
*-commutative88.1%
Applied egg-rr88.1%
Taylor expanded in y around inf 87.1%
if -5.79999999999999995e-72 < z < 8.8000000000000003e97Initial program 100.0%
Taylor expanded in x around inf 88.8%
mul-1-neg88.8%
unsub-neg88.8%
Simplified88.8%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -82.0) (not (<= y 0.00112))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -82.0) || !(y <= 0.00112)) {
tmp = y * (z - x);
} 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 ((y <= (-82.0d0)) .or. (.not. (y <= 0.00112d0))) then
tmp = y * (z - x)
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -82.0) || !(y <= 0.00112)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -82.0) or not (y <= 0.00112): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -82.0) || !(y <= 0.00112)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -82.0) || ~((y <= 0.00112))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -82.0], N[Not[LessEqual[y, 0.00112]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -82 \lor \neg \left(y \leq 0.00112\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -82 or 0.0011199999999999999 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt-in89.9%
Applied egg-rr89.9%
associate-+r+89.9%
distribute-lft-neg-out89.9%
unsub-neg89.9%
+-commutative89.9%
*-commutative89.9%
Applied egg-rr89.9%
Taylor expanded in y around inf 99.4%
if -82 < y < 0.0011199999999999999Initial program 100.0%
Taylor expanded in z around inf 99.0%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.7e-71) (not (<= z 5e+97))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.7e-71) || !(z <= 5e+97)) {
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 ((z <= (-1.7d-71)) .or. (.not. (z <= 5d+97))) 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 ((z <= -1.7e-71) || !(z <= 5e+97)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.7e-71) or not (z <= 5e+97): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.7e-71) || !(z <= 5e+97)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.7e-71) || ~((z <= 5e+97))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.7e-71], N[Not[LessEqual[z, 5e+97]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.7 \cdot 10^{-71} \lor \neg \left(z \leq 5 \cdot 10^{+97}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.70000000000000002e-71 or 4.99999999999999999e97 < z Initial program 100.0%
sub-neg100.0%
distribute-rgt-in88.1%
Applied egg-rr88.1%
associate-+r+88.1%
distribute-lft-neg-out88.1%
unsub-neg88.1%
+-commutative88.1%
*-commutative88.1%
Applied egg-rr88.1%
Taylor expanded in z around inf 75.5%
if -1.70000000000000002e-71 < z < 4.99999999999999999e97Initial program 100.0%
Taylor expanded in y around 0 50.6%
Final simplification61.2%
(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 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 y around 0 35.4%
Final simplification35.4%
herbie shell --seed 2024053
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))