
(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 -1.9e+158)
(* y z)
(if (<= y -220000000000.0)
t_0
(if (<= y -0.0066)
(* y z)
(if (<= y 1.16e-125)
x
(if (or (<= y 7e+15) (and (not (<= y 2.85e+116)) (<= y 9e+167)))
(* y z)
t_0)))))))
double code(double x, double y, double z) {
double t_0 = y * -x;
double tmp;
if (y <= -1.9e+158) {
tmp = y * z;
} else if (y <= -220000000000.0) {
tmp = t_0;
} else if (y <= -0.0066) {
tmp = y * z;
} else if (y <= 1.16e-125) {
tmp = x;
} else if ((y <= 7e+15) || (!(y <= 2.85e+116) && (y <= 9e+167))) {
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 <= (-1.9d+158)) then
tmp = y * z
else if (y <= (-220000000000.0d0)) then
tmp = t_0
else if (y <= (-0.0066d0)) then
tmp = y * z
else if (y <= 1.16d-125) then
tmp = x
else if ((y <= 7d+15) .or. (.not. (y <= 2.85d+116)) .and. (y <= 9d+167)) 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 <= -1.9e+158) {
tmp = y * z;
} else if (y <= -220000000000.0) {
tmp = t_0;
} else if (y <= -0.0066) {
tmp = y * z;
} else if (y <= 1.16e-125) {
tmp = x;
} else if ((y <= 7e+15) || (!(y <= 2.85e+116) && (y <= 9e+167))) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * -x tmp = 0 if y <= -1.9e+158: tmp = y * z elif y <= -220000000000.0: tmp = t_0 elif y <= -0.0066: tmp = y * z elif y <= 1.16e-125: tmp = x elif (y <= 7e+15) or (not (y <= 2.85e+116) and (y <= 9e+167)): 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 <= -1.9e+158) tmp = Float64(y * z); elseif (y <= -220000000000.0) tmp = t_0; elseif (y <= -0.0066) tmp = Float64(y * z); elseif (y <= 1.16e-125) tmp = x; elseif ((y <= 7e+15) || (!(y <= 2.85e+116) && (y <= 9e+167))) 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 <= -1.9e+158) tmp = y * z; elseif (y <= -220000000000.0) tmp = t_0; elseif (y <= -0.0066) tmp = y * z; elseif (y <= 1.16e-125) tmp = x; elseif ((y <= 7e+15) || (~((y <= 2.85e+116)) && (y <= 9e+167))) 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, -1.9e+158], N[(y * z), $MachinePrecision], If[LessEqual[y, -220000000000.0], t$95$0, If[LessEqual[y, -0.0066], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.16e-125], x, If[Or[LessEqual[y, 7e+15], And[N[Not[LessEqual[y, 2.85e+116]], $MachinePrecision], LessEqual[y, 9e+167]]], N[(y * z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(-x\right)\\
\mathbf{if}\;y \leq -1.9 \cdot 10^{+158}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq -220000000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -0.0066:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{-125}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+15} \lor \neg \left(y \leq 2.85 \cdot 10^{+116}\right) \land y \leq 9 \cdot 10^{+167}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.8999999999999999e158 or -2.2e11 < y < -0.0066 or 1.15999999999999995e-125 < y < 7e15 or 2.84999999999999991e116 < y < 8.9999999999999998e167Initial program 100.0%
Taylor expanded in z around inf 79.4%
Taylor expanded in x around 0 67.7%
if -1.8999999999999999e158 < y < -2.2e11 or 7e15 < y < 2.84999999999999991e116 or 8.9999999999999998e167 < y Initial program 100.0%
Taylor expanded in z around 0 68.3%
mul-1-neg68.3%
distribute-lft-neg-out68.3%
*-commutative68.3%
Simplified68.3%
Taylor expanded in y around inf 68.1%
associate-*r*68.1%
mul-1-neg68.1%
Simplified68.1%
if -0.0066 < y < 1.15999999999999995e-125Initial program 100.0%
Taylor expanded in z around inf 98.7%
Taylor expanded in x around inf 77.4%
Final simplification71.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ x (* y z))) (t_1 (* y (- x))))
(if (<= y -7.5e+149)
t_0
(if (<= y -900000000000.0)
t_1
(if (<= y 6.5e+15)
t_0
(if (or (<= y 1.22e+116) (not (<= y 1.15e+168))) 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 <= -7.5e+149) {
tmp = t_0;
} else if (y <= -900000000000.0) {
tmp = t_1;
} else if (y <= 6.5e+15) {
tmp = t_0;
} else if ((y <= 1.22e+116) || !(y <= 1.15e+168)) {
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 <= (-7.5d+149)) then
tmp = t_0
else if (y <= (-900000000000.0d0)) then
tmp = t_1
else if (y <= 6.5d+15) then
tmp = t_0
else if ((y <= 1.22d+116) .or. (.not. (y <= 1.15d+168))) 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 <= -7.5e+149) {
tmp = t_0;
} else if (y <= -900000000000.0) {
tmp = t_1;
} else if (y <= 6.5e+15) {
tmp = t_0;
} else if ((y <= 1.22e+116) || !(y <= 1.15e+168)) {
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 <= -7.5e+149: tmp = t_0 elif y <= -900000000000.0: tmp = t_1 elif y <= 6.5e+15: tmp = t_0 elif (y <= 1.22e+116) or not (y <= 1.15e+168): 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 <= -7.5e+149) tmp = t_0; elseif (y <= -900000000000.0) tmp = t_1; elseif (y <= 6.5e+15) tmp = t_0; elseif ((y <= 1.22e+116) || !(y <= 1.15e+168)) 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 <= -7.5e+149) tmp = t_0; elseif (y <= -900000000000.0) tmp = t_1; elseif (y <= 6.5e+15) tmp = t_0; elseif ((y <= 1.22e+116) || ~((y <= 1.15e+168))) 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, -7.5e+149], t$95$0, If[LessEqual[y, -900000000000.0], t$95$1, If[LessEqual[y, 6.5e+15], t$95$0, If[Or[LessEqual[y, 1.22e+116], N[Not[LessEqual[y, 1.15e+168]], $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 -7.5 \cdot 10^{+149}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -900000000000:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 6.5 \cdot 10^{+15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.22 \cdot 10^{+116} \lor \neg \left(y \leq 1.15 \cdot 10^{+168}\right):\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < -7.50000000000000031e149 or -9e11 < y < 6.5e15Initial program 100.0%
Taylor expanded in z around inf 90.6%
if -7.50000000000000031e149 < y < -9e11 or 6.5e15 < y < 1.21999999999999993e116 or 1.15e168 < y Initial program 100.0%
Taylor expanded in z around 0 68.3%
mul-1-neg68.3%
distribute-lft-neg-out68.3%
*-commutative68.3%
Simplified68.3%
Taylor expanded in y around inf 68.1%
associate-*r*68.1%
mul-1-neg68.1%
Simplified68.1%
if 1.21999999999999993e116 < y < 1.15e168Initial program 100.0%
Taylor expanded in z around inf 78.8%
Taylor expanded in x around 0 79.2%
Final simplification82.3%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.28e-17) (not (<= x 2.05e+108))) (- x (* x y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.28e-17) || !(x <= 2.05e+108)) {
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 <= (-1.28d-17)) .or. (.not. (x <= 2.05d+108))) 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 <= -1.28e-17) || !(x <= 2.05e+108)) {
tmp = x - (x * y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.28e-17) or not (x <= 2.05e+108): tmp = x - (x * y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.28e-17) || !(x <= 2.05e+108)) 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 <= -1.28e-17) || ~((x <= 2.05e+108))) tmp = x - (x * y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.28e-17], N[Not[LessEqual[x, 2.05e+108]], $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 -1.28 \cdot 10^{-17} \lor \neg \left(x \leq 2.05 \cdot 10^{+108}\right):\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -1.28e-17 or 2.05e108 < x Initial program 100.0%
Taylor expanded in z around 0 92.3%
mul-1-neg92.3%
distribute-lft-neg-out92.3%
*-commutative92.3%
Simplified92.3%
*-commutative92.3%
distribute-lft-neg-out92.3%
unsub-neg92.3%
Applied egg-rr92.3%
if -1.28e-17 < x < 2.05e108Initial program 100.0%
Taylor expanded in z around inf 89.0%
Final simplification90.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0066) (not (<= y 1.16e-125))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0066) || !(y <= 1.16e-125)) {
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 <= (-0.0066d0)) .or. (.not. (y <= 1.16d-125))) 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 <= -0.0066) || !(y <= 1.16e-125)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0066) or not (y <= 1.16e-125): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0066) || !(y <= 1.16e-125)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0066) || ~((y <= 1.16e-125))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0066], N[Not[LessEqual[y, 1.16e-125]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0066 \lor \neg \left(y \leq 1.16 \cdot 10^{-125}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.0066 or 1.15999999999999995e-125 < y Initial program 100.0%
Taylor expanded in z around inf 57.2%
Taylor expanded in x around 0 51.4%
if -0.0066 < y < 1.15999999999999995e-125Initial program 100.0%
Taylor expanded in z around inf 98.7%
Taylor expanded in x around inf 77.4%
Final simplification60.6%
(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 71.8%
Taylor expanded in x around inf 32.4%
Final simplification32.4%
herbie shell --seed 2024041
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))