
(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%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- x))))
(if (<= y -3.6e+102)
t_0
(if (<= y -1.85e+93)
(* y z)
(if (or (<= y -3850000.0) (not (<= y 1.0))) t_0 x)))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -3.6e+102) {
tmp = t_0;
} else if (y <= -1.85e+93) {
tmp = y * z;
} else if ((y <= -3850000.0) || !(y <= 1.0)) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = y * -x
if (y <= (-3.6d+102)) then
tmp = t_0
else if (y <= (-1.85d+93)) then
tmp = y * z
else if ((y <= (-3850000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = t_0
else
tmp = x
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+102) {
tmp = t_0;
} else if (y <= -1.85e+93) {
tmp = y * z;
} else if ((y <= -3850000.0) || !(y <= 1.0)) {
tmp = t_0;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -3.6e+102: tmp = t_0 elif y <= -1.85e+93: tmp = y * z elif (y <= -3850000.0) or not (y <= 1.0): tmp = t_0 else: tmp = x return tmp
function code(x, y, z) t_0 = Float64(y * Float64(-x)) tmp = 0.0 if (y <= -3.6e+102) tmp = t_0; elseif (y <= -1.85e+93) tmp = Float64(y * z); elseif ((y <= -3850000.0) || !(y <= 1.0)) tmp = t_0; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * -x; tmp = 0.0; if (y <= -3.6e+102) tmp = t_0; elseif (y <= -1.85e+93) tmp = y * z; elseif ((y <= -3850000.0) || ~((y <= 1.0))) tmp = t_0; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * (-x)), $MachinePrecision]}, If[LessEqual[y, -3.6e+102], t$95$0, If[LessEqual[y, -1.85e+93], N[(y * z), $MachinePrecision], If[Or[LessEqual[y, -3850000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], t$95$0, x]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -3.6 \cdot 10^{+102}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.85 \cdot 10^{+93}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -3850000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.6000000000000002e102 or -1.84999999999999994e93 < y < -3.85e6 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.1%
Taylor expanded in z around 0 64.7%
mul-1-neg64.7%
distribute-lft-neg-out64.7%
*-commutative64.7%
Simplified64.7%
if -3.6000000000000002e102 < y < -1.84999999999999994e93Initial program 99.7%
Taylor expanded in x around 0 87.6%
if -3.85e6 < y < 1Initial program 100.0%
Taylor expanded in y around 0 72.1%
Final simplification68.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -1300.0) (not (<= y 1100000000.0))) (* y (- z x)) (- x (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1300.0) || !(y <= 1100000000.0)) {
tmp = y * (z - x);
} else {
tmp = x - (y * 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 <= (-1300.0d0)) .or. (.not. (y <= 1100000000.0d0))) then
tmp = y * (z - x)
else
tmp = x - (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -1300.0) || !(y <= 1100000000.0)) {
tmp = y * (z - x);
} else {
tmp = x - (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1300.0) or not (y <= 1100000000.0): tmp = y * (z - x) else: tmp = x - (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1300.0) || !(y <= 1100000000.0)) tmp = Float64(y * Float64(z - x)); else tmp = Float64(x - Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1300.0) || ~((y <= 1100000000.0))) tmp = y * (z - x); else tmp = x - (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1300.0], N[Not[LessEqual[y, 1100000000.0]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x - N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1300 \lor \neg \left(y \leq 1100000000\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot x\\
\end{array}
\end{array}
if y < -1300 or 1.1e9 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
if -1300 < y < 1.1e9Initial program 100.0%
Taylor expanded in x around inf 74.9%
mul-1-neg74.9%
unsub-neg74.9%
Simplified74.9%
sub-neg74.9%
distribute-rgt-in74.9%
*-un-lft-identity74.9%
Applied egg-rr74.9%
distribute-lft-neg-out74.9%
unsub-neg74.9%
Applied egg-rr74.9%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -128000.0) (not (<= y 1100000000.0))) (* y (- z x)) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -128000.0) || !(y <= 1100000000.0)) {
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 ((y <= (-128000.0d0)) .or. (.not. (y <= 1100000000.0d0))) 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 ((y <= -128000.0) || !(y <= 1100000000.0)) {
tmp = y * (z - x);
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -128000.0) or not (y <= 1100000000.0): tmp = y * (z - x) else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -128000.0) || !(y <= 1100000000.0)) 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 ((y <= -128000.0) || ~((y <= 1100000000.0))) tmp = y * (z - x); else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -128000.0], N[Not[LessEqual[y, 1100000000.0]], $MachinePrecision]], N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -128000 \lor \neg \left(y \leq 1100000000\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if y < -128000 or 1.1e9 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
if -128000 < y < 1.1e9Initial program 100.0%
Taylor expanded in x around inf 74.9%
mul-1-neg74.9%
unsub-neg74.9%
Simplified74.9%
Final simplification87.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -8e-125) (not (<= x 1.35e-131))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-125) || !(x <= 1.35e-131)) {
tmp = x * (1.0 - y);
} 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) :: tmp
if ((x <= (-8d-125)) .or. (.not. (x <= 1.35d-131))) then
tmp = x * (1.0d0 - y)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -8e-125) || !(x <= 1.35e-131)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -8e-125) or not (x <= 1.35e-131): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -8e-125) || !(x <= 1.35e-131)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -8e-125) || ~((x <= 1.35e-131))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -8e-125], N[Not[LessEqual[x, 1.35e-131]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8 \cdot 10^{-125} \lor \neg \left(x \leq 1.35 \cdot 10^{-131}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -8.0000000000000001e-125 or 1.35000000000000011e-131 < x Initial program 100.0%
Taylor expanded in x around inf 83.8%
mul-1-neg83.8%
unsub-neg83.8%
Simplified83.8%
if -8.0000000000000001e-125 < x < 1.35000000000000011e-131Initial program 100.0%
Taylor expanded in x around 0 68.8%
Final simplification79.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.3e-6) (not (<= y 0.2))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.3e-6) || !(y <= 0.2)) {
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 <= (-5.3d-6)) .or. (.not. (y <= 0.2d0))) 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 <= -5.3e-6) || !(y <= 0.2)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.3e-6) or not (y <= 0.2): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.3e-6) || !(y <= 0.2)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.3e-6) || ~((y <= 0.2))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.3e-6], N[Not[LessEqual[y, 0.2]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.3 \cdot 10^{-6} \lor \neg \left(y \leq 0.2\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -5.3000000000000001e-6 or 0.20000000000000001 < y Initial program 100.0%
Taylor expanded in x around 0 41.9%
if -5.3000000000000001e-6 < y < 0.20000000000000001Initial program 100.0%
Taylor expanded in y around 0 72.6%
Final simplification57.1%
(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%
(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 37.7%
herbie shell --seed 2024100
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))