
(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 7 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%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- y))))
(if (<= x -1.15e+171)
t_0
(if (<= x -4.4e+34)
x
(if (<= x 1.22e-120) (* y z) (if (<= x 2.8e-52) x t_0))))))
double code(double x, double y, double z) {
double t_0 = x * -y;
double tmp;
if (x <= -1.15e+171) {
tmp = t_0;
} else if (x <= -4.4e+34) {
tmp = x;
} else if (x <= 1.22e-120) {
tmp = y * z;
} else if (x <= 2.8e-52) {
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 = x * -y
if (x <= (-1.15d+171)) then
tmp = t_0
else if (x <= (-4.4d+34)) then
tmp = x
else if (x <= 1.22d-120) then
tmp = y * z
else if (x <= 2.8d-52) 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 = x * -y;
double tmp;
if (x <= -1.15e+171) {
tmp = t_0;
} else if (x <= -4.4e+34) {
tmp = x;
} else if (x <= 1.22e-120) {
tmp = y * z;
} else if (x <= 2.8e-52) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -y tmp = 0 if x <= -1.15e+171: tmp = t_0 elif x <= -4.4e+34: tmp = x elif x <= 1.22e-120: tmp = y * z elif x <= 2.8e-52: tmp = x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-y)) tmp = 0.0 if (x <= -1.15e+171) tmp = t_0; elseif (x <= -4.4e+34) tmp = x; elseif (x <= 1.22e-120) tmp = Float64(y * z); elseif (x <= 2.8e-52) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -y; tmp = 0.0; if (x <= -1.15e+171) tmp = t_0; elseif (x <= -4.4e+34) tmp = x; elseif (x <= 1.22e-120) tmp = y * z; elseif (x <= 2.8e-52) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-y)), $MachinePrecision]}, If[LessEqual[x, -1.15e+171], t$95$0, If[LessEqual[x, -4.4e+34], x, If[LessEqual[x, 1.22e-120], N[(y * z), $MachinePrecision], If[LessEqual[x, 2.8e-52], x, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-y\right)\\
\mathbf{if}\;x \leq -1.15 \cdot 10^{+171}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -4.4 \cdot 10^{+34}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.22 \cdot 10^{-120}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;x \leq 2.8 \cdot 10^{-52}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.15000000000000009e171 or 2.79999999999999995e-52 < x Initial program 100.0%
Taylor expanded in x around inf 88.1%
mul-1-neg88.1%
unsub-neg88.1%
Simplified88.1%
Taylor expanded in y around inf 52.5%
neg-mul-152.5%
distribute-lft-neg-in52.5%
Simplified52.5%
if -1.15000000000000009e171 < x < -4.4000000000000005e34 or 1.21999999999999996e-120 < x < 2.79999999999999995e-52Initial program 100.0%
Taylor expanded in y around 0 61.7%
if -4.4000000000000005e34 < x < 1.21999999999999996e-120Initial program 100.0%
Taylor expanded in z around inf 92.9%
Taylor expanded in x around 0 76.8%
Final simplification64.4%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.9e+33) (not (<= x 2.1e-63))) (* x (- 1.0 y)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.9e+33) || !(x <= 2.1e-63)) {
tmp = x * (1.0 - 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 <= (-2.9d+33)) .or. (.not. (x <= 2.1d-63))) then
tmp = x * (1.0d0 - 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 <= -2.9e+33) || !(x <= 2.1e-63)) {
tmp = x * (1.0 - y);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.9e+33) or not (x <= 2.1e-63): tmp = x * (1.0 - y) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.9e+33) || !(x <= 2.1e-63)) tmp = Float64(x * Float64(1.0 - y)); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.9e+33) || ~((x <= 2.1e-63))) tmp = x * (1.0 - y); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.9e+33], N[Not[LessEqual[x, 2.1e-63]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9 \cdot 10^{+33} \lor \neg \left(x \leq 2.1 \cdot 10^{-63}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if x < -2.90000000000000025e33 or 2.1e-63 < x Initial program 100.0%
Taylor expanded in x around inf 89.1%
mul-1-neg89.1%
unsub-neg89.1%
Simplified89.1%
if -2.90000000000000025e33 < x < 2.1e-63Initial program 100.0%
Taylor expanded in z around inf 93.5%
Final simplification91.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -2.45e-33) (not (<= x 1.26e-120))) (* x (- 1.0 y)) (* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.45e-33) || !(x <= 1.26e-120)) {
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 <= (-2.45d-33)) .or. (.not. (x <= 1.26d-120))) 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 <= -2.45e-33) || !(x <= 1.26e-120)) {
tmp = x * (1.0 - y);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.45e-33) or not (x <= 1.26e-120): tmp = x * (1.0 - y) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.45e-33) || !(x <= 1.26e-120)) 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 <= -2.45e-33) || ~((x <= 1.26e-120))) tmp = x * (1.0 - y); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.45e-33], N[Not[LessEqual[x, 1.26e-120]], $MachinePrecision]], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.45 \cdot 10^{-33} \lor \neg \left(x \leq 1.26 \cdot 10^{-120}\right):\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -2.4499999999999999e-33 or 1.25999999999999992e-120 < x Initial program 100.0%
Taylor expanded in x around inf 85.1%
mul-1-neg85.1%
unsub-neg85.1%
Simplified85.1%
if -2.4499999999999999e-33 < x < 1.25999999999999992e-120Initial program 100.0%
Taylor expanded in z around inf 96.6%
Taylor expanded in x around 0 82.9%
Final simplification84.2%
(FPCore (x y z) :precision binary64 (if (<= x -6.2e+31) (* x (- 1.0 y)) (if (<= x 3.5e-63) (+ x (* y z)) (- x (* x y)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e+31) {
tmp = x * (1.0 - y);
} else if (x <= 3.5e-63) {
tmp = x + (y * z);
} else {
tmp = x - (x * 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 (x <= (-6.2d+31)) then
tmp = x * (1.0d0 - y)
else if (x <= 3.5d-63) then
tmp = x + (y * z)
else
tmp = x - (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -6.2e+31) {
tmp = x * (1.0 - y);
} else if (x <= 3.5e-63) {
tmp = x + (y * z);
} else {
tmp = x - (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -6.2e+31: tmp = x * (1.0 - y) elif x <= 3.5e-63: tmp = x + (y * z) else: tmp = x - (x * y) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -6.2e+31) tmp = Float64(x * Float64(1.0 - y)); elseif (x <= 3.5e-63) tmp = Float64(x + Float64(y * z)); else tmp = Float64(x - Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -6.2e+31) tmp = x * (1.0 - y); elseif (x <= 3.5e-63) tmp = x + (y * z); else tmp = x - (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -6.2e+31], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.5e-63], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{+31}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-63}:\\
\;\;\;\;x + y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x - x \cdot y\\
\end{array}
\end{array}
if x < -6.2000000000000004e31Initial program 100.0%
Taylor expanded in x around inf 96.2%
mul-1-neg96.2%
unsub-neg96.2%
Simplified96.2%
if -6.2000000000000004e31 < x < 3.50000000000000003e-63Initial program 100.0%
Taylor expanded in z around inf 93.5%
if 3.50000000000000003e-63 < x Initial program 100.0%
Taylor expanded in x around inf 84.5%
mul-1-neg84.5%
unsub-neg84.5%
Simplified84.5%
sub-neg84.5%
distribute-rgt-in84.6%
*-un-lft-identity84.6%
distribute-lft-neg-in84.6%
unsub-neg84.6%
*-commutative84.6%
Applied egg-rr84.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.25e-121) (not (<= y 1.26e-54))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.25e-121) || !(y <= 1.26e-54)) {
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 <= (-1.25d-121)) .or. (.not. (y <= 1.26d-54))) 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 <= -1.25e-121) || !(y <= 1.26e-54)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.25e-121) or not (y <= 1.26e-54): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.25e-121) || !(y <= 1.26e-54)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.25e-121) || ~((y <= 1.26e-54))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.25e-121], N[Not[LessEqual[y, 1.26e-54]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{-121} \lor \neg \left(y \leq 1.26 \cdot 10^{-54}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.24999999999999997e-121 or 1.2599999999999999e-54 < y Initial program 100.0%
Taylor expanded in z around inf 57.2%
Taylor expanded in x around 0 50.4%
if -1.24999999999999997e-121 < y < 1.2599999999999999e-54Initial program 100.0%
Taylor expanded in y around 0 74.2%
Final simplification58.9%
(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 32.4%
herbie shell --seed 2024180
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))