
(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
(if (or (<= x -310000000000.0)
(not
(or (<= x -3.25e-217) (and (not (<= x -1.95e-245)) (<= x 2.15e-7)))))
(* x (- 1.0 z))
(* y z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -310000000000.0) || !((x <= -3.25e-217) || (!(x <= -1.95e-245) && (x <= 2.15e-7)))) {
tmp = x * (1.0 - z);
} 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 <= (-310000000000.0d0)) .or. (.not. (x <= (-3.25d-217)) .or. (.not. (x <= (-1.95d-245))) .and. (x <= 2.15d-7))) then
tmp = x * (1.0d0 - z)
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -310000000000.0) || !((x <= -3.25e-217) || (!(x <= -1.95e-245) && (x <= 2.15e-7)))) {
tmp = x * (1.0 - z);
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -310000000000.0) or not ((x <= -3.25e-217) or (not (x <= -1.95e-245) and (x <= 2.15e-7))): tmp = x * (1.0 - z) else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -310000000000.0) || !((x <= -3.25e-217) || (!(x <= -1.95e-245) && (x <= 2.15e-7)))) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -310000000000.0) || ~(((x <= -3.25e-217) || (~((x <= -1.95e-245)) && (x <= 2.15e-7))))) tmp = x * (1.0 - z); else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -310000000000.0], N[Not[Or[LessEqual[x, -3.25e-217], And[N[Not[LessEqual[x, -1.95e-245]], $MachinePrecision], LessEqual[x, 2.15e-7]]]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -310000000000 \lor \neg \left(x \leq -3.25 \cdot 10^{-217} \lor \neg \left(x \leq -1.95 \cdot 10^{-245}\right) \land x \leq 2.15 \cdot 10^{-7}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -3.1e11 or -3.2499999999999998e-217 < x < -1.9499999999999999e-245 or 2.1500000000000001e-7 < x Initial program 100.0%
Taylor expanded in x around inf 87.1%
mul-1-neg87.1%
unsub-neg87.1%
Simplified87.1%
if -3.1e11 < x < -3.2499999999999998e-217 or -1.9499999999999999e-245 < x < 2.1500000000000001e-7Initial program 100.0%
Taylor expanded in z around inf 99.9%
associate--l+99.9%
+-commutative99.9%
associate-+l-99.9%
Simplified99.9%
Taylor expanded in x around 0 73.6%
Final simplification80.5%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (- z))))
(if (<= z -1.0)
t_0
(if (<= z 3.4e-36)
x
(if (or (<= z 1.35e+99) (not (<= z 6e+244))) (* y z) t_0)))))
double code(double x, double y, double z) {
double t_0 = x * -z;
double tmp;
if (z <= -1.0) {
tmp = t_0;
} else if (z <= 3.4e-36) {
tmp = x;
} else if ((z <= 1.35e+99) || !(z <= 6e+244)) {
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 <= (-1.0d0)) then
tmp = t_0
else if (z <= 3.4d-36) then
tmp = x
else if ((z <= 1.35d+99) .or. (.not. (z <= 6d+244))) 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 <= -1.0) {
tmp = t_0;
} else if (z <= 3.4e-36) {
tmp = x;
} else if ((z <= 1.35e+99) || !(z <= 6e+244)) {
tmp = y * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * -z tmp = 0 if z <= -1.0: tmp = t_0 elif z <= 3.4e-36: tmp = x elif (z <= 1.35e+99) or not (z <= 6e+244): 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 <= -1.0) tmp = t_0; elseif (z <= 3.4e-36) tmp = x; elseif ((z <= 1.35e+99) || !(z <= 6e+244)) 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 <= -1.0) tmp = t_0; elseif (z <= 3.4e-36) tmp = x; elseif ((z <= 1.35e+99) || ~((z <= 6e+244))) 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, -1.0], t$95$0, If[LessEqual[z, 3.4e-36], x, If[Or[LessEqual[z, 1.35e+99], N[Not[LessEqual[z, 6e+244]], $MachinePrecision]], N[(y * z), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(-z\right)\\
\mathbf{if}\;z \leq -1:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{-36}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{+99} \lor \neg \left(z \leq 6 \cdot 10^{+244}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1 or 1.34999999999999994e99 < z < 5.9999999999999995e244Initial program 100.0%
Taylor expanded in z around inf 99.9%
associate--l+99.9%
+-commutative99.9%
associate-+l-99.9%
Simplified99.9%
Taylor expanded in z around inf 98.9%
distribute-lft-out--98.9%
Applied egg-rr98.9%
Taylor expanded in y around 0 58.6%
associate-*r*58.6%
neg-mul-158.6%
*-commutative58.6%
Simplified58.6%
if -1 < z < 3.4000000000000003e-36Initial program 100.0%
Taylor expanded in z around 0 72.2%
if 3.4000000000000003e-36 < z < 1.34999999999999994e99 or 5.9999999999999995e244 < z Initial program 100.0%
Taylor expanded in z around inf 98.3%
associate--l+98.3%
+-commutative98.3%
associate-+l-98.3%
Simplified98.3%
Taylor expanded in x around 0 75.3%
Final simplification68.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e+45) (not (<= x 1.16e+32))) (* x (- 1.0 z)) (* (- y x) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e+45) || !(x <= 1.16e+32)) {
tmp = x * (1.0 - z);
} else {
tmp = (y - x) * 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.95d+45)) .or. (.not. (x <= 1.16d+32))) then
tmp = x * (1.0d0 - z)
else
tmp = (y - x) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e+45) || !(x <= 1.16e+32)) {
tmp = x * (1.0 - z);
} else {
tmp = (y - x) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.95e+45) or not (x <= 1.16e+32): tmp = x * (1.0 - z) else: tmp = (y - x) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e+45) || !(x <= 1.16e+32)) tmp = Float64(x * Float64(1.0 - z)); else tmp = Float64(Float64(y - x) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.95e+45) || ~((x <= 1.16e+32))) tmp = x * (1.0 - z); else tmp = (y - x) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.95e+45], N[Not[LessEqual[x, 1.16e+32]], $MachinePrecision]], N[(x * N[(1.0 - z), $MachinePrecision]), $MachinePrecision], N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{+45} \lor \neg \left(x \leq 1.16 \cdot 10^{+32}\right):\\
\;\;\;\;x \cdot \left(1 - z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y - x\right) \cdot z\\
\end{array}
\end{array}
if x < -1.95e45 or 1.16e32 < x Initial program 100.0%
Taylor expanded in x around inf 93.3%
mul-1-neg93.3%
unsub-neg93.3%
Simplified93.3%
if -1.95e45 < x < 1.16e32Initial program 99.9%
Taylor expanded in z around inf 99.9%
associate--l+99.9%
+-commutative99.9%
associate-+l-99.9%
Simplified99.9%
Taylor expanded in z around inf 80.2%
Final simplification85.5%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 5.8e-5))) (* (- y x) z) (+ x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 5.8e-5)) {
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 <= (-1.0d0)) .or. (.not. (z <= 5.8d-5))) 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 <= -1.0) || !(z <= 5.8e-5)) {
tmp = (y - x) * z;
} else {
tmp = x + (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 5.8e-5): tmp = (y - x) * z else: tmp = x + (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 5.8e-5)) 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 <= -1.0) || ~((z <= 5.8e-5))) tmp = (y - x) * z; else tmp = x + (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 5.8e-5]], $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 -1 \lor \neg \left(z \leq 5.8 \cdot 10^{-5}\right):\\
\;\;\;\;\left(y - x\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot z\\
\end{array}
\end{array}
if z < -1 or 5.8e-5 < 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 -1 < z < 5.8e-5Initial program 100.0%
Taylor expanded in y around inf 99.6%
*-commutative99.6%
Simplified99.6%
Final simplification99.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.6e-18) (not (<= z 3.8e-37))) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e-18) || !(z <= 3.8e-37)) {
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 <= (-2.6d-18)) .or. (.not. (z <= 3.8d-37))) 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 <= -2.6e-18) || !(z <= 3.8e-37)) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.6e-18) or not (z <= 3.8e-37): tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.6e-18) || !(z <= 3.8e-37)) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.6e-18) || ~((z <= 3.8e-37))) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.6e-18], N[Not[LessEqual[z, 3.8e-37]], $MachinePrecision]], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{-18} \lor \neg \left(z \leq 3.8 \cdot 10^{-37}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.6e-18 or 3.8000000000000004e-37 < z Initial program 99.9%
Taylor expanded in z around inf 99.3%
associate--l+99.3%
+-commutative99.3%
associate-+l-99.3%
Simplified99.3%
Taylor expanded in x around 0 55.9%
if -2.6e-18 < z < 3.8000000000000004e-37Initial program 100.0%
Taylor expanded in z around 0 74.6%
Final simplification64.0%
(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 34.9%
Final simplification34.9%
herbie shell --seed 2024067
(FPCore (x y z)
:name "Diagrams.ThreeD.Shapes:frustum from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ x (* (- y x) z)))