
(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
(if (<= y -3e-40)
(* y z)
(if (<= y 1.35e-193)
x
(if (<= y 2.8e-137)
(* y z)
(if (<= y 1.6e-23)
x
(if (or (<= y 7e+151) (not (<= y 1.1e+207))) (* y z) (* y (- x))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -3e-40) {
tmp = y * z;
} else if (y <= 1.35e-193) {
tmp = x;
} else if (y <= 2.8e-137) {
tmp = y * z;
} else if (y <= 1.6e-23) {
tmp = x;
} else if ((y <= 7e+151) || !(y <= 1.1e+207)) {
tmp = y * z;
} else {
tmp = 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 <= (-3d-40)) then
tmp = y * z
else if (y <= 1.35d-193) then
tmp = x
else if (y <= 2.8d-137) then
tmp = y * z
else if (y <= 1.6d-23) then
tmp = x
else if ((y <= 7d+151) .or. (.not. (y <= 1.1d+207))) then
tmp = y * z
else
tmp = y * -x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -3e-40) {
tmp = y * z;
} else if (y <= 1.35e-193) {
tmp = x;
} else if (y <= 2.8e-137) {
tmp = y * z;
} else if (y <= 1.6e-23) {
tmp = x;
} else if ((y <= 7e+151) || !(y <= 1.1e+207)) {
tmp = y * z;
} else {
tmp = y * -x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -3e-40: tmp = y * z elif y <= 1.35e-193: tmp = x elif y <= 2.8e-137: tmp = y * z elif y <= 1.6e-23: tmp = x elif (y <= 7e+151) or not (y <= 1.1e+207): tmp = y * z else: tmp = y * -x return tmp
function code(x, y, z) tmp = 0.0 if (y <= -3e-40) tmp = Float64(y * z); elseif (y <= 1.35e-193) tmp = x; elseif (y <= 2.8e-137) tmp = Float64(y * z); elseif (y <= 1.6e-23) tmp = x; elseif ((y <= 7e+151) || !(y <= 1.1e+207)) tmp = Float64(y * z); else tmp = Float64(y * Float64(-x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -3e-40) tmp = y * z; elseif (y <= 1.35e-193) tmp = x; elseif (y <= 2.8e-137) tmp = y * z; elseif (y <= 1.6e-23) tmp = x; elseif ((y <= 7e+151) || ~((y <= 1.1e+207))) tmp = y * z; else tmp = y * -x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -3e-40], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.35e-193], x, If[LessEqual[y, 2.8e-137], N[(y * z), $MachinePrecision], If[LessEqual[y, 1.6e-23], x, If[Or[LessEqual[y, 7e+151], N[Not[LessEqual[y, 1.1e+207]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y * (-x)), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-40}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-193}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-137}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 1.6 \cdot 10^{-23}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+151} \lor \neg \left(y \leq 1.1 \cdot 10^{+207}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-x\right)\\
\end{array}
\end{array}
if y < -3.0000000000000002e-40 or 1.35e-193 < y < 2.7999999999999999e-137 or 1.59999999999999988e-23 < y < 7.0000000000000006e151 or 1.10000000000000004e207 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt-in97.0%
Applied egg-rr97.0%
associate-+r+97.0%
distribute-lft-neg-out97.0%
unsub-neg97.0%
+-commutative97.0%
*-commutative97.0%
Applied egg-rr97.0%
Taylor expanded in z around inf 62.9%
if -3.0000000000000002e-40 < y < 1.35e-193 or 2.7999999999999999e-137 < y < 1.59999999999999988e-23Initial program 100.0%
Taylor expanded in y around 0 75.8%
if 7.0000000000000006e151 < y < 1.10000000000000004e207Initial program 100.0%
Taylor expanded in x around inf 87.0%
mul-1-neg87.0%
unsub-neg87.0%
Simplified87.0%
sub-neg87.0%
distribute-rgt-in87.0%
*-un-lft-identity87.0%
distribute-lft-neg-in87.0%
unsub-neg87.0%
Applied egg-rr87.0%
Taylor expanded in y around inf 87.0%
mul-1-neg87.0%
distribute-rgt-neg-out87.0%
Simplified87.0%
Final simplification69.3%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* y (- z x))))
(if (<= y -8.5e-34)
t_0
(if (<= y 1.35e-193)
x
(if (<= y 1.36e-142) (* y z) (if (<= y 5000.0) (* x (- 1.0 y)) t_0))))))
double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -8.5e-34) {
tmp = t_0;
} else if (y <= 1.35e-193) {
tmp = x;
} else if (y <= 1.36e-142) {
tmp = y * z;
} else if (y <= 5000.0) {
tmp = x * (1.0 - y);
} 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 * (z - x)
if (y <= (-8.5d-34)) then
tmp = t_0
else if (y <= 1.35d-193) then
tmp = x
else if (y <= 1.36d-142) then
tmp = y * z
else if (y <= 5000.0d0) then
tmp = x * (1.0d0 - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z - x);
double tmp;
if (y <= -8.5e-34) {
tmp = t_0;
} else if (y <= 1.35e-193) {
tmp = x;
} else if (y <= 1.36e-142) {
tmp = y * z;
} else if (y <= 5000.0) {
tmp = x * (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z - x) tmp = 0 if y <= -8.5e-34: tmp = t_0 elif y <= 1.35e-193: tmp = x elif y <= 1.36e-142: tmp = y * z elif y <= 5000.0: tmp = x * (1.0 - y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z - x)) tmp = 0.0 if (y <= -8.5e-34) tmp = t_0; elseif (y <= 1.35e-193) tmp = x; elseif (y <= 1.36e-142) tmp = Float64(y * z); elseif (y <= 5000.0) tmp = Float64(x * Float64(1.0 - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z - x); tmp = 0.0; if (y <= -8.5e-34) tmp = t_0; elseif (y <= 1.35e-193) tmp = x; elseif (y <= 1.36e-142) tmp = y * z; elseif (y <= 5000.0) tmp = x * (1.0 - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -8.5e-34], t$95$0, If[LessEqual[y, 1.35e-193], x, If[LessEqual[y, 1.36e-142], N[(y * z), $MachinePrecision], If[LessEqual[y, 5000.0], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z - x\right)\\
\mathbf{if}\;y \leq -8.5 \cdot 10^{-34}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-193}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.36 \cdot 10^{-142}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;y \leq 5000:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -8.5000000000000001e-34 or 5e3 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt-in96.8%
Applied egg-rr96.8%
associate-+r+96.8%
distribute-lft-neg-out96.8%
unsub-neg96.8%
+-commutative96.8%
*-commutative96.8%
Applied egg-rr96.8%
Taylor expanded in y around inf 97.6%
if -8.5000000000000001e-34 < y < 1.35e-193Initial program 100.0%
Taylor expanded in y around 0 79.7%
if 1.35e-193 < y < 1.35999999999999993e-142Initial program 100.0%
sub-neg100.0%
distribute-rgt-in100.0%
Applied egg-rr100.0%
associate-+r+100.0%
distribute-lft-neg-out100.0%
unsub-neg100.0%
+-commutative100.0%
*-commutative100.0%
Applied egg-rr100.0%
Taylor expanded in z around inf 72.6%
if 1.35999999999999993e-142 < y < 5e3Initial program 100.0%
Taylor expanded in x around inf 66.5%
mul-1-neg66.5%
unsub-neg66.5%
Simplified66.5%
Final simplification86.1%
(FPCore (x y z)
:precision binary64
(if (or (<= y -1.05e-38)
(not (or (<= y 1.2e-193) (and (not (<= y 9.2e-143)) (<= y 8e-24)))))
(* y z)
x))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.05e-38) || !((y <= 1.2e-193) || (!(y <= 9.2e-143) && (y <= 8e-24)))) {
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.05d-38)) .or. (.not. (y <= 1.2d-193) .or. (.not. (y <= 9.2d-143)) .and. (y <= 8d-24))) 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.05e-38) || !((y <= 1.2e-193) || (!(y <= 9.2e-143) && (y <= 8e-24)))) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.05e-38) or not ((y <= 1.2e-193) or (not (y <= 9.2e-143) and (y <= 8e-24))): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.05e-38) || !((y <= 1.2e-193) || (!(y <= 9.2e-143) && (y <= 8e-24)))) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.05e-38) || ~(((y <= 1.2e-193) || (~((y <= 9.2e-143)) && (y <= 8e-24))))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.05e-38], N[Not[Or[LessEqual[y, 1.2e-193], And[N[Not[LessEqual[y, 9.2e-143]], $MachinePrecision], LessEqual[y, 8e-24]]]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-38} \lor \neg \left(y \leq 1.2 \cdot 10^{-193} \lor \neg \left(y \leq 9.2 \cdot 10^{-143}\right) \land y \leq 8 \cdot 10^{-24}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.05000000000000006e-38 or 1.2e-193 < y < 9.20000000000000045e-143 or 7.99999999999999939e-24 < y Initial program 100.0%
sub-neg100.0%
distribute-rgt-in97.2%
Applied egg-rr97.2%
associate-+r+97.2%
distribute-lft-neg-out97.2%
unsub-neg97.2%
+-commutative97.2%
*-commutative97.2%
Applied egg-rr97.2%
Taylor expanded in z around inf 60.3%
if -1.05000000000000006e-38 < y < 1.2e-193 or 9.20000000000000045e-143 < y < 7.99999999999999939e-24Initial program 100.0%
Taylor expanded in y around 0 75.8%
Final simplification67.1%
(FPCore (x y z) :precision binary64 (if (or (<= z -1e+24) (not (<= z 2.55e+92))) (* y z) (* x (- 1.0 y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1e+24) || !(z <= 2.55e+92)) {
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 <= (-1d+24)) .or. (.not. (z <= 2.55d+92))) 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 <= -1e+24) || !(z <= 2.55e+92)) {
tmp = y * z;
} else {
tmp = x * (1.0 - y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1e+24) or not (z <= 2.55e+92): tmp = y * z else: tmp = x * (1.0 - y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1e+24) || !(z <= 2.55e+92)) 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 <= -1e+24) || ~((z <= 2.55e+92))) tmp = y * z; else tmp = x * (1.0 - y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1e+24], N[Not[LessEqual[z, 2.55e+92]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{+24} \lor \neg \left(z \leq 2.55 \cdot 10^{+92}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\end{array}
\end{array}
if z < -9.9999999999999998e23 or 2.5500000000000001e92 < z Initial program 100.0%
sub-neg100.0%
distribute-rgt-in96.5%
Applied egg-rr96.5%
associate-+r+96.5%
distribute-lft-neg-out96.5%
unsub-neg96.5%
+-commutative96.5%
*-commutative96.5%
Applied egg-rr96.5%
Taylor expanded in z around inf 76.6%
if -9.9999999999999998e23 < z < 2.5500000000000001e92Initial program 100.0%
Taylor expanded in x around inf 80.2%
mul-1-neg80.2%
unsub-neg80.2%
Simplified80.2%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -96.0) (not (<= y 1.0))) (* y (- z x)) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -96.0) || !(y <= 1.0)) {
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 <= (-96.0d0)) .or. (.not. (y <= 1.0d0))) 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 <= -96.0) || !(y <= 1.0)) {
tmp = y * (z - x);
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -96.0) or not (y <= 1.0): tmp = y * (z - x) else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -96.0) || !(y <= 1.0)) 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 <= -96.0) || ~((y <= 1.0))) tmp = y * (z - x); else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -96.0], N[Not[LessEqual[y, 1.0]], $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 -96 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if y < -96 or 1 < y Initial program 99.9%
sub-neg99.9%
distribute-rgt-in96.6%
Applied egg-rr96.6%
associate-+r+96.6%
distribute-lft-neg-out96.6%
unsub-neg96.6%
+-commutative96.6%
*-commutative96.6%
Applied egg-rr96.6%
Taylor expanded in y around inf 98.2%
if -96 < y < 1Initial program 100.0%
Taylor expanded in z around inf 97.6%
Final simplification97.9%
(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 37.0%
Final simplification37.0%
herbie shell --seed 2024080
(FPCore (x y z)
:name "SynthBasics:oscSampleBasedAux from YampaSynth-0.2"
:precision binary64
(+ x (* y (- z x))))