
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma (- y x) z x))
double code(double x, double y, double z) {
return fma((y - x), z, x);
}
function code(x, y, z) return fma(Float64(y - x), z, x) end
code[x_, y_, z_] := N[(N[(y - x), $MachinePrecision] * z + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y - x, z, 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 (* x (- z))))
(if (<= z -2.5e+238)
t_0
(if (<= z -2.8e+150)
(* y z)
(if (<= z -6e+119)
t_0
(if (<= z -5.8e+70)
(* y z)
(if (<= z -8.6e+19)
t_0
(if (<= z -1.75e-65)
(* y z)
(if (<= z 8.6e-97) x (if (<= z 4.2e+229) (* y z) t_0))))))))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -2.5e+238) {
tmp = t_0;
} else if (z <= -2.8e+150) {
tmp = y * z;
} else if (z <= -6e+119) {
tmp = t_0;
} else if (z <= -5.8e+70) {
tmp = y * z;
} else if (z <= -8.6e+19) {
tmp = t_0;
} else if (z <= -1.75e-65) {
tmp = y * z;
} else if (z <= 8.6e-97) {
tmp = x;
} else if (z <= 4.2e+229) {
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 = x * -z
if (z <= (-2.5d+238)) then
tmp = t_0
else if (z <= (-2.8d+150)) then
tmp = y * z
else if (z <= (-6d+119)) then
tmp = t_0
else if (z <= (-5.8d+70)) then
tmp = y * z
else if (z <= (-8.6d+19)) then
tmp = t_0
else if (z <= (-1.75d-65)) then
tmp = y * z
else if (z <= 8.6d-97) then
tmp = x
else if (z <= 4.2d+229) 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 = x * -z;
double tmp;
if (z <= -2.5e+238) {
tmp = t_0;
} else if (z <= -2.8e+150) {
tmp = y * z;
} else if (z <= -6e+119) {
tmp = t_0;
} else if (z <= -5.8e+70) {
tmp = y * z;
} else if (z <= -8.6e+19) {
tmp = t_0;
} else if (z <= -1.75e-65) {
tmp = y * z;
} else if (z <= 8.6e-97) {
tmp = x;
} else if (z <= 4.2e+229) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -2.5e+238: tmp = t_0 elif z <= -2.8e+150: tmp = y * z elif z <= -6e+119: tmp = t_0 elif z <= -5.8e+70: tmp = y * z elif z <= -8.6e+19: tmp = t_0 elif z <= -1.75e-65: tmp = y * z elif z <= 8.6e-97: tmp = x elif z <= 4.2e+229: tmp = y * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * Float64(-z)) tmp = 0.0 if (z <= -2.5e+238) tmp = t_0; elseif (z <= -2.8e+150) tmp = Float64(y * z); elseif (z <= -6e+119) tmp = t_0; elseif (z <= -5.8e+70) tmp = Float64(y * z); elseif (z <= -8.6e+19) tmp = t_0; elseif (z <= -1.75e-65) tmp = Float64(y * z); elseif (z <= 8.6e-97) tmp = x; elseif (z <= 4.2e+229) tmp = Float64(y * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * -z; tmp = 0.0; if (z <= -2.5e+238) tmp = t_0; elseif (z <= -2.8e+150) tmp = y * z; elseif (z <= -6e+119) tmp = t_0; elseif (z <= -5.8e+70) tmp = y * z; elseif (z <= -8.6e+19) tmp = t_0; elseif (z <= -1.75e-65) tmp = y * z; elseif (z <= 8.6e-97) tmp = x; elseif (z <= 4.2e+229) tmp = y * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * (-z)), $MachinePrecision]}, If[LessEqual[z, -2.5e+238], t$95$0, If[LessEqual[z, -2.8e+150], N[(y * z), $MachinePrecision], If[LessEqual[z, -6e+119], t$95$0, If[LessEqual[z, -5.8e+70], N[(y * z), $MachinePrecision], If[LessEqual[z, -8.6e+19], t$95$0, If[LessEqual[z, -1.75e-65], N[(y * z), $MachinePrecision], If[LessEqual[z, 8.6e-97], x, If[LessEqual[z, 4.2e+229], N[(y * z), $MachinePrecision], t$95$0]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -2.5 \cdot 10^{+238}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -2.8 \cdot 10^{+150}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -6 \cdot 10^{+119}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -5.8 \cdot 10^{+70}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -8.6 \cdot 10^{+19}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -1.75 \cdot 10^{-65}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 8.6 \cdot 10^{-97}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 4.2 \cdot 10^{+229}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -2.49999999999999998e238 or -2.80000000000000009e150 < z < -6.00000000000000002e119 or -5.7999999999999997e70 < z < -8.6e19 or 4.19999999999999975e229 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
associate--l+100.0%
+-commutative100.0%
associate-+l-100.0%
Simplified100.0%
Taylor expanded in z around inf 100.0%
distribute-lft-out--96.0%
Applied egg-rr96.0%
Taylor expanded in y around 0 84.6%
associate-*r*84.6%
neg-mul-184.6%
*-commutative84.6%
Simplified84.6%
if -2.49999999999999998e238 < z < -2.80000000000000009e150 or -6.00000000000000002e119 < z < -5.7999999999999997e70 or -8.6e19 < z < -1.75000000000000002e-65 or 8.6e-97 < z < 4.19999999999999975e229Initial program 99.9%
Taylor expanded in z around inf 99.2%
associate--l+99.2%
+-commutative99.2%
associate-+l-99.2%
Simplified99.2%
Taylor expanded in x around 0 66.5%
if -1.75000000000000002e-65 < z < 8.6e-97Initial program 100.0%
Taylor expanded in z around 0 82.1%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.8e+77) (not (<= y 2.2e+72))) (* y z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e+77) || !(y <= 2.2e+72)) {
tmp = y * z;
} else {
tmp = x * (1.0 - 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 <= (-2.8d+77)) .or. (.not. (y <= 2.2d+72))) then
tmp = y * z
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -2.8e+77) || !(y <= 2.2e+72)) {
tmp = y * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -2.8e+77) or not (y <= 2.2e+72): tmp = y * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -2.8e+77) || !(y <= 2.2e+72)) tmp = Float64(y * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -2.8e+77) || ~((y <= 2.2e+72))) tmp = y * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.8e+77], N[Not[LessEqual[y, 2.2e+72]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+77} \lor \neg \left(y \leq 2.2 \cdot 10^{+72}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if y < -2.8e77 or 2.2e72 < y Initial program 100.0%
Taylor expanded in z around inf 83.8%
associate--l+83.8%
+-commutative83.8%
associate-+l-83.8%
Simplified83.8%
Taylor expanded in x around 0 77.3%
if -2.8e77 < y < 2.2e72Initial program 100.0%
Taylor expanded in x around inf 78.2%
mul-1-neg78.2%
unsub-neg78.2%
Simplified78.2%
Final simplification77.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -6.6e-66) (not (<= z 8.6e-97))) (* (- y x) z) (* x (- 1.0 z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6.6e-66) || !(z <= 8.6e-97)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - 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 ((z <= (-6.6d-66)) .or. (.not. (z <= 8.6d-97))) then
tmp = (y - x) * z
else
tmp = x * (1.0d0 - z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6.6e-66) || !(z <= 8.6e-97)) {
tmp = (y - x) * z;
} else {
tmp = x * (1.0 - z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6.6e-66) or not (z <= 8.6e-97): tmp = (y - x) * z else: tmp = x * (1.0 - z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6.6e-66) || !(z <= 8.6e-97)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x * Float64(1.0 - z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6.6e-66) || ~((z <= 8.6e-97))) tmp = (y - x) * z; else tmp = x * (1.0 - z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6.6e-66], N[Not[LessEqual[z, 8.6e-97]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.6 \cdot 10^{-66} \lor \neg \left(z \leq 8.6 \cdot 10^{-97}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\end{array}
\end{array}
if z < -6.5999999999999998e-66 or 8.6e-97 < z Initial program 100.0%
Taylor expanded in z around inf 99.5%
associate--l+99.5%
+-commutative99.5%
associate-+l-99.5%
Simplified99.5%
Taylor expanded in z around inf 94.3%
if -6.5999999999999998e-66 < z < 8.6e-97Initial program 100.0%
Taylor expanded in x around inf 82.1%
mul-1-neg82.1%
unsub-neg82.1%
Simplified82.1%
Final simplification90.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -940000.0) (not (<= z 6.4e-18))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -940000.0) || !(z <= 6.4e-18)) {
tmp = (y - x) * z;
} 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 ((z <= (-940000.0d0)) .or. (.not. (z <= 6.4d-18))) then
tmp = (y - x) * z
else
tmp = x + (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -940000.0) || !(z <= 6.4e-18)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -940000.0) or not (z <= 6.4e-18): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -940000.0) || !(z <= 6.4e-18)) tmp = Float64(Float64(y - x) * z); else tmp = Float64(x + Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -940000.0) || ~((z <= 6.4e-18))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -940000.0], N[Not[LessEqual[z, 6.4e-18]], $MachinePrecision]], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision], N[(x + N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -940000 \lor \neg \left(z \leq 6.4 \cdot 10^{-18}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -9.4e5 or 6.3999999999999998e-18 < z Initial program 100.0%
Taylor expanded in z around inf 100.0%
associate--l+100.0%
+-commutative100.0%
associate-+l-100.0%
Simplified100.0%
Taylor expanded in z around inf 99.2%
if -9.4e5 < z < 6.3999999999999998e-18Initial program 100.0%
Taylor expanded in y around inf 99.7%
*-commutative99.7%
Simplified99.7%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.25e-65) (not (<= z 3.05e-99))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.25e-65) || !(z <= 3.05e-99)) {
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.25d-65)) .or. (.not. (z <= 3.05d-99))) 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.25e-65) || !(z <= 3.05e-99)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.25e-65) or not (z <= 3.05e-99): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.25e-65) || !(z <= 3.05e-99)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.25e-65) || ~((z <= 3.05e-99))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.25e-65], N[Not[LessEqual[z, 3.05e-99]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.25 \cdot 10^{-65} \lor \neg \left(z \leq 3.05 \cdot 10^{-99}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.24999999999999996e-65 or 3.0500000000000002e-99 < z Initial program 100.0%
Taylor expanded in z around inf 99.5%
associate--l+99.5%
+-commutative99.5%
associate-+l-99.5%
Simplified99.5%
Taylor expanded in x around 0 57.1%
if -1.24999999999999996e-65 < z < 3.0500000000000002e-99Initial program 100.0%
Taylor expanded in z around 0 82.1%
Final simplification65.3%
(FPCore (x y z) :precision binary64 (+ x (* (- y x) z)))
double code(double x, double y, double z) {
return x + ((y - x) * z);
}
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 - x) * z)
end function
public static double code(double x, double y, double z) {
return x + ((y - x) * z);
}
def code(x, y, z): return x + ((y - x) * z)
function code(x, y, z) return Float64(x + Float64(Float64(y - x) * z)) end
function tmp = code(x, y, z) tmp = x + ((y - x) * z); end
code[x_, y_, z_] := N[(x + N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot z
\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 z around 0 32.3%
Final simplification32.3%
herbie shell --seed 2024071
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))